组织学校工作空间/编写 Makefile

发布于 2024-08-08 08:09:17 字数 1008 浏览 6 评论 0原文

我正在为学校做一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听,心雨的声音 2024-08-15 08:09:17

用户可以使用 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.

妄想挽回 2024-08-15 08:09:17

为什么您不想(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文