为 C/C 中的项目的 makefile 生成依赖项;
我有一个项目,其 makefile 的依赖关系已损坏。 除了手动或手写 perl 脚本检查每个源文件之外,是否有任何最著名的方法来生成可以在 makefile 中使用的项目依赖项列表?
I have a project that has a makefile with broken dependencies. Is there any best known way to generate a list of dependencies for the project that I can use in the makefile, other than examining each source file by hand or with a hand written perl script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
GNU make 的文档提供了一个很好的解决方案。
绝对地。
g++ -MM
将生成 GMake 兼容的依赖项列表。 我使用这样的东西:注意:
$(CXX)
/gcc
命令必须是 前面有一个硬制表符这将自动为每个已更改的文件生成依赖项,并根据您现有的任何规则编译它们。 这允许我将新文件转储到 src/ 目录中,并自动编译它们、依赖项等。
GNU make's documentation provides a good solution.
Absolutely.
g++ -MM <your file>
will generate a GMake compatible list of dependencies. I use something like this:Note:
$(CXX)
/gcc
command must be preceded with a hard tabWhat this will do is automatically generate the dependencies for each file that has changed, and compile them according to whatever rule you have in place. This allows me to just dump new files into the
src/
directory, and have them compiled automatically, dependencies and all.现在阅读了这一部分后,我认为有一个更简单的解决方案,只要你有一个gcc/g++ 的最新版本。 如果您只是将
-MMD
添加到CFLAGS
中,定义一个代表所有对象文件的变量OBJS
,然后执行以下操作:那么这应该可以让您既是一个高效又简单的自动依赖关系构建系统。
Having now read this portion in particular I think there is a much easier solution out there, as long as you have a reasonably up to date version of gcc/g++. If you just add
-MMD
to yourCFLAGS
, define a variableOBJS
representing all your object files, and then do:then that should get you both an efficient and simple automatic dependency build system.
GNU C 预处理器 cpp 有一个选项 -MM,它根据包含模式生成一组适合 make 的依赖项。
The GNU C preprocessor cpp has an option, -MM, which produces a make-suitable set of dependencies based on inclusion patterns.
我只需将其添加到 makefile 中,它就可以很好地工作:
I just add this to the makefile and it works nicely:
Digital Mars C/C++ 编译器附带 makedep 工具。
The Digital Mars C/C++ compiler comes with a makedep tool.