如何自动化生成文件?
如何使 makefile 遍历 .cpp 文件列表并单独编译,就像静态那样?
test: test.o
g++ -o test test.o
test.o: test.cc test.hh
g++ -c test.cc
但从这个动态?
SOURCES = main.cpp someClass.cpp otherFile.cpp
How do you make a makefile go through a list of .cpp files and compile then separately, just like this does statically?
test: test.o
g++ -o test test.o
test.o: test.cc test.hh
g++ -c test.cc
but dynamically from this?
SOURCES = main.cpp someClass.cpp otherFile.cpp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您也想为每个模块强制使用类似名称的标头,那么您可以:
If you want to enforce like-named headers for each module, too, then you can:
automake 使这变得更加容易:
将从列出的源构建
程序
文件。唯一的问题是它与 autoconf 一起工作,这可能需要一些时间才能正确设置。 (至少,我第一次从来没有做对过。)automake makes this even easier:
will build
program
from the listed source files. The only problem is that it works in conjunction with autoconf, which may take some time to set up properly. (At least, I never get it right the first time.)您也可以尝试:
这样您就不必指定任何 cpp 名称。您添加的任何新源文件都会被自动选取。然而,这仅适用于 Unix shell。
You could also try:
This way you don't have to specify any cpp names. Any new source files you add will automatically be picked up. However, this would only work in Unix shells.