组织学校工作空间/编写 Makefile
我正在为学校做一些 C 编程,我发现自己一遍又一遍地重复使用我创建的库(堆栈、用户输入、错误处理等)。
现在,我个人的 SVN 目录结构如下所示:
trunk/
|-- 2520
| `-- assignments
| |-- A2
| |-- Makefile
| |-- README
| |-- calculator.c
| |-- calculatorlib.c
| `-- calculatorlib.h
`-- libs
|-- misc
| |-- errorlib.c
| |-- errorlib.h
| |-- userinputlib.c
| `-- userinputlib.h
`-- stacks
|-- stacklib.c
`-- stacklib.h
由于显而易见的原因,其中一些文件(userinputlib 和 errorlib)几乎在我从事的每个项目中都会使用。我希望能够将这些文件包含在项目的工作区 (2520/assignments/A2) 中,而不必复制这些文件,因为我不想管理文件的副本,也不想签入两个副本SVN 中的同一文件。
我希望将库文件放在项目工作区中,这样我的 Makefile 就可以工作,而无需进行太多手动配置(或硬编码路径)。
起初,我考虑了符号链接(SVN 和 tar 支持),但鉴于我的标头位于另一个目录中,我似乎无法编译我的作业。
我可以手动将每个标头编译为目标文件并进行最终链接,但我不确定如何在 Makefile 中自动执行此操作。
对于我如何设置环境的任何帮助或任何替代方案,我们将不胜感激。
谢谢!
编辑:我忘了提及我已经搜索了Google并找到了一些描述使用gcc -MM
自动依赖项生成的页面(也许我想要这个?)并且我已经阅读翻遍了 GNU Make 手册,但我什么也没想到。
I am doing some C programming for school and I have found myself reusing libraries that I have created, over and over again (stacks, user input, error handling, etc).
Right now, my personal SVN directory structure looks like this:
trunk/
|-- 2520
| `-- assignments
| |-- A2
| |-- Makefile
| |-- README
| |-- calculator.c
| |-- calculatorlib.c
| `-- calculatorlib.h
`-- libs
|-- misc
| |-- errorlib.c
| |-- errorlib.h
| |-- userinputlib.c
| `-- userinputlib.h
`-- stacks
|-- stacklib.c
`-- stacklib.h
Some of these files (userinputlib and errorlib) get used in almost every project I work on for obvious reasons. I want to be able to include these files in a project's workspace (2520/assignments/A2) without having to copy the files because I don't want to manage to copies of a file and I don't want to check in two copies of the same file in SVN.
I would like to have the library files in the project workspace so my Makefile works without having to do to much manual configuration (or hard-coding paths).
At first, I thought about symbolic links (which SVN and tar support) but I can't seem to compile my assignment given my headers in another directory.
I can manually compile each header to an object file and do the final linking, but I'm not sure how to do this in a Makefile automatically.
Any help or any alternative to how I have my environment setup is appreciated.
Thanks!
EDIT: I forgot to mention that I have searched Google and have found a few pages describing automatic dependency generation (perhaps I want this?) using gcc -MM
and I have read over the GNU Make manual but nothing jumped out at me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用户可以使用 subversion 的 externals 功能来链接动态将 libs 树复制为项目的子目录。
但最终最好只使用一个副本(一个颠覆副本,因此它实际上是库代码的一个分支),这样您就不必担心库的更改会影响现有项目,并且可以根据需要合并更改。
Use could use subversion's externals feature to link a dynamic copy of the libs tree as a subdirectory of your project.
But in the end it may be better to just use a copy (a subversion copy, so it would effectively be a branch of the library code), so that you don't need to worry about changes to the library affecting existing projects, and can merge changes around as needed.
为什么您不想(svn)将必要的库复制到您的项目中?您实际上将创建库的一个分支以在项目中使用。如果您最终在库代码中发现了错误,您可以就地修复它,然后将其提交回(到副本)。完成后,您可以将修复合并回库的主干位置。
Why wouldn't you want to (svn) copy the necessary libs into your project? You'll essentially be creating a branch of your lib for use in your project. If you end up discovering a bug in your library code, you can fix it in place, and commit it back (to the copy). Once you're wrapping up, you can merge your fixes back to the library's trunk location.