使用递归 makefile,如何将目标文件文件夹传递给调用 make?
我正在使用递归 Makefile 构建一个项目。基本格式很简单:源文件在各个子目录中,Makefile 在项目根目录中。从项目根目录调用 make 将调用子目录中的所有 makefile。到目前为止,一切都很好。
现在我有了目标文件。如何使主 makefile 看到子目录中存在哪些目标文件,以便更好地将它们传递给链接器?
I'm building a project with a recursive Makefile. The basic format is simple: source files in various subdirectories, Makefile in the project root. Calling make from the project root will call all the makefile in the subdirectories. So far so good.
So now I've got object files. How can I make the main makefile see which object files live in the subdirectories, the better to pass them to the linker?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上不是一个好方法(请参阅递归 make 被认为有害),因为递归 makefile 增加了开销多次启动 Make 程序。实际上,通过包含另一个 Makefile 中的一个 Makefile 而不是从另一个 Makefile 中调用它,您可以更快地完成同样的事情。如果您包含子目录中的 make 文件,这也将解决全局 make 文件查看其所需的所有文件以将它们链接在一起的问题。您可以使用一个变量来表示所有目标文件,并且您包含的每个 make 文件都可以附加到该变量中。
另外,请允许我建议使用 CMake。它使配置构建机制变得更加简单且不易出错,但仍然允许您使用 Make 进行构建(它为您生成 Makefile)。
This is actually not a good approach (see recursive make considered harmful), because recursive makefiles adds the overhead of launching the Make program multiple times. You can actually accomplish the same thing, much faster, by including one Makefile from another rather than invoking it from another. If you include the make files from subdirectories, that will also solve the problem of your global make file seeing all of the files it needs in order to link them together. You can have a single variable that represents all the object files, and each make file that you include can append to this.
Also, allow me to suggest using CMake. It makes configuring your build mechanism significantly simpler and less error prone, but still allows you to build with Make (it generates Makefiles for you).