在将文件链接到最终可执行文件之前将它们合并到单个目录中

发布于 2024-08-31 04:02:55 字数 946 浏览 1 评论 0原文

我正在开发 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那些过往 2024-09-07 04:02:55

简短的回答:这是一种常见的做法,通常很方便,但并不总是好的,也不总是坏的。

另外,如果您使用自动变量和模式规则,您的 makefile 可以更短、更清晰:

COMPILE = CC -I/../../include -library=stlport4 -instances=extern

%.o: %.cc
    $(COMPILE) -c 
lt;

unit_test: unit_test.o my_model.o symbol_dictionary.o
    $(COMPILE) -o $@ $^

symbol_dictionary.o:
    cd ../../test-fixtures && ($MAKE) $@
    mv ../../test-fixtures/$@ .

在 ../../test 中:

COMPILE = CC -I/../../include -library=stlport4 -instances=extern

symbol_dictionary.o: %.o : %.cc
    $(COMPILE) -c 
lt;

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:

COMPILE = CC -I/../../include -library=stlport4 -instances=extern

%.o: %.cc
    $(COMPILE) -c 
lt;

unit_test: unit_test.o my_model.o symbol_dictionary.o
    $(COMPILE) -o $@ $^

symbol_dictionary.o:
    cd ../../test-fixtures && ($MAKE) $@
    mv ../../test-fixtures/$@ .

in ../../test:

COMPILE = CC -I/../../include -library=stlport4 -instances=extern

symbol_dictionary.o: %.o : %.cc
    $(COMPILE) -c 
lt;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文