g ++部分链接而不是档案?

g++ partial linking instead of archives?(g ++部分链接而不是档案?)

本文介绍了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.

如果您在 ar<中同时拥有带有符号 foofoo.o 和带有符号 bar 的 bar.o/code> 存档,并且只引用 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.

您也可以尝试更快的链接器,例如 gold.

You could also try a faster linker, like gold.

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

本文标题为:g ++部分链接而不是档案?

基础教程推荐