非标准目录布局中的 makefile
一个非常相似的问题,但与经常被问到的问题并不完全相同;我的项目具有以下布局(跨平台,因此不同的 IDE 等)
[Project]
|
|--- codeblocks
| |- obj
|--- src
|--- visual_studio
本质上,我试图获取我的 makefile(位于 codeblocks 目录中),编译 src 中包含的文件,并将目标文件放入进入obj目录。
编译方面我可以毫无问题地实现,但我一生都无法弄清楚如何告诉 make 使用此替代目录作为对象文件<的默认位置< /em>;之后我可以移动它们,但这意味着每次构建时我都必须重新编译整个应用程序,这会破坏 makefile 的对象。
通读 make 文档(是的,我确实首先尝试过,并在途中学到了一些额外的东西!),我遇到了一些示例,例如 $(OBJDIR)/%.o: %.c
,但是 make 无法找到使用它的规则,而且我还没有足够的经验来自己解决这个问题:(
谁能指出我在正确的方向或提供一些合适的提示?
A very similar question, but not exact to those asked frequently; my project has the following layout (cross-platform, hence different IDEs, etc.)
[Project]
|
|--- codeblocks
| |- obj
|--- src
|--- visual_studio
Essentially, I'm trying to get my makefile (located in the codeblocks directory), to compile the files contained within src, and have the object files put into the obj directory.
The compilation side I can acheive with no problem, but I can't for the life of me figure out how to tell make to use this alternative directory as the default location for the object files; moving them afterwards I can do, but means I have to recompile the entire application each time I do a build, which defeats the object of the makefile.
Reading through the make documentation (yes, I did try first, and learnt some extra things on the way!), I came across some examples, such as$(OBJDIR)/%.o: %.c
, but make is unable to find the rule to utilize it, and I am nowhere near experienced enough to work it out for myself :(
Can anyone point me in the right direction or provide some suitable hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是一个简单的 Makefile 示例,演示了如何执行此操作。
Makefile 所需的目录结构和文件是:
我在我的机器上测试了它,它运行正确:
Here is a simple example Makefile demonstrating how to do this.
The directory structure and files needed by the Makefile are:
I tested this on my machine and it ran correctly:
如果您使用 GNU make,则可以使用您所描述的扩展模式规则。然后你可以有一个规则
来编译源文件。额外的复杂性是您的链接规则还需要为所有目标文件指定 $(OBJDIR)。您可以使用类似的东西
,或者,您可以使用
VPATH
来避免在所有这些地方需要$(SRCDIR)。If you are using GNU make, you can use the extended pattern rules like you describe. You can then have a rule
To compile the source files. The additional complication is that you linking rule needs to also specify $(OBJDIR) for all the object files. You can use something like
Alternately, you can use
VPATH
to avoid the need for $(SRCDIR) in all these places.