g ++部分链接而不是归档? [英] g++ partial linking instead of archives?

查看:71
本文介绍了g ++部分链接而不是归档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C ++构建流程很熟悉,我正在考虑改用为我的库使用部分链接,而不是创建 ar 档案。我希望减少链接时间在一个不可避免的最终编译步骤,我有,我认为部分链接一些库一次可以节省我的时间,在最后一步连接的一切。

I'm pretty new to the C++ build flow, and I'm thinking of switching to use partial linking for my libraries instead of creating ar archives. I'm hoping to reduce link time in an inevitable final compilation step that I have, and I figure partial linking some libraries once could save me time over linking everything in that final step.

我的描述是可能的吗?我认为应该是沿着 ld -Ur -o mylib.o [components] 行的东西。是否有重要的构建注意事项,我没有考虑?

Is what I'm describing possible? I figure it should be something along the lines ld -Ur -o mylib.o [components]. Are there important build considerations that I'm not taking into account?

推荐答案

您失去了一个重要的影响, ar 存档,这是只有被​​引用的对象将被链接。

You lose an important effect of having the object files in an ar archive, which is that only the referenced objects will be linked in.

c $ c> foo.o ,符号 foo 和bar.o符号 bar ar 存档中,只引用 foo 符号,只有 foo.o 将被链接到。如果你改为做一个部分链接,两者的内容将在可执行文件中结束,即使 bar 从未引用

If you have both foo.o with the symbol foo and bar.o with the symbol bar in an ar archive, and only reference the foo symbol, only foo.o would be linked in. If you instead do a partial link, the contents of both will end up in the executable, even if bar is never referenced anywhere.

您还可以尝试更快的链接器,例如黄金

You could also try a faster linker, like gold.

这篇关于g ++部分链接而不是归档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆