在将文件链接到最终可执行文件之前将它们合并到单个目录中
我正在开发 Solaris 10、Sun Studio 11。我正在重构一些旧代码,并尝试为它们编写单元测试。我的 make 文件如下所示:
my_model.o:my_model.cc
CC -c my_model.cc -I/../../include -library=stlport4 -instances=extern
unit_test: unit_test.o my_model.o symbol_dictionary.o
CC -o unit_test unit_test.o my_model.o symbol_dictionary.o -I../../include \
-library=stlport4 -instances=extern
unit_test.o: unit_test.cc
CC -c unit_test.cc -I/../../include -library=stlport4 -instances=extern
symbol_dictionary.o:
cd ../../test-fixtures && ($MAKE) symbol_dictionary.o
mv ../../test-fixtures/symbol_dictionary.o .
在 ../../test-fixtures makefile 中,我有以下目标:
symbol_dictionary.o:
CC -c symbol_dictionary.cc -I/../../include -library=stlport4 -instances=extern
我执行instances=extern,因为我之前遇到过链接问题,这是推荐的解决方案。结果是在正在编译的每个目录中,都会创建一个 SunWS_Cache 目录来存储模板实例。
要回答这个问题还有很长的路要走。在链接目标文件之前将它们合并到单个目录中是否是标准做法?
I am working on Solaris 10, Sun Studio 11. I am refactoring some old code, and trying to write unit tests for them. My make file looks like:
my_model.o:my_model.cc
CC -c my_model.cc -I/../../include -library=stlport4 -instances=extern
unit_test: unit_test.o my_model.o symbol_dictionary.o
CC -o unit_test unit_test.o my_model.o symbol_dictionary.o -I../../include \
-library=stlport4 -instances=extern
unit_test.o: unit_test.cc
CC -c unit_test.cc -I/../../include -library=stlport4 -instances=extern
symbol_dictionary.o:
cd ../../test-fixtures && ($MAKE) symbol_dictionary.o
mv ../../test-fixtures/symbol_dictionary.o .
In the ../../test-fixtures makefile, I have the following target:
symbol_dictionary.o:
CC -c symbol_dictionary.cc -I/../../include -library=stlport4 -instances=extern
I do the instances=extern because I had linking problems before, and this was the recommended solution. The consequence is in each directory that is being compiled, a SunWS_Cache directory is created to store the template instances.
This is the long way to get to this question. Is it a standard practice to consolidate object files in a single directory before you link them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答:这是一种常见的做法,通常很方便,但并不总是好的,也不总是坏的。
另外,如果您使用自动变量和模式规则,您的 makefile 可以更短、更清晰:
在 ../../test 中:
Short answer: it is a common practice, often convenient, not always good, not always bad.
Also, your makefiles can be shorter and cleaner if you use automatic variables and pattern rules:
in ../../test: