如何加快 C++ 链接时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/921693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to speed up c++ linking time
提问by Ludek Vodicka
Is there any way, to optimalize linking time in MS Visual studio C++ (2005) ? We're using Xoreax Incredibuild for compilation speed up, but nothing for link.
有什么办法可以优化 MS Visual Studio C++ (2005) 中的链接时间?我们使用 Xoreax Incredibuild 来加快编译速度,但没有用于链接。
Currently every linking takes about 30seconds. When I turn on incremental linking, takes abou 35-40 seconds. ( No matter if i compile project with or without incredibuild )
目前每个链接大约需要 30 秒。当我打开增量链接时,大约需要 35-40 秒。(无论我是否使用 Incredibuild 编译项目)
Is there any way, how to profile linker and watch how long what takes ? Or any tool for paralel linking ? Or any tips for code optimalization to speed up linker ?
有什么办法,如何配置链接器并观看需要多长时间?或者任何用于并行链接的工具?或者任何关于代码优化以加速链接器的提示?
Thanks for reply Ludek Vodicka
感谢回复 Ludek Vodicka
Edit:
编辑:
Thanks for first replies, and additional info:
感谢您的第一次回复和补充信息:
- Whole Program Optimization and link-time code generation is already off.
- PIMPL idiom is already used when possible
- other static libraries are already included via #pragma comment(lib, "pathToLib"). (also because of easier maintenance]
- HW : quad core q6600, 8GB ram, 3x WD raptor raid 0. Windows Vista 64bit
- 整个程序优化和链接时代码生成已经关闭。
- PIMPL 习语已在可能的情况下使用
- 其他静态库已通过#pragma comment(lib, "pathToLib") 包含在内。(也是因为更容易维护】
- 硬件:四核 q6600,8GB 内存,3x WD raptor raid 0。Windows Vista 64 位
采纳答案by Brett Douville
I'm not aware of any parallel linking tools; I do know that Incredibuild does not allow it.
我不知道有任何并行链接工具;我知道 Incredibuild 不允许这样做。
The biggest tool in your toolbox for avoiding link times is the appropriate level of abstraction. If your link times are long, it may be because objects know too much about other objects. Decoupling them is then the key -- through abstract interfaces (perhaps using the PIMPL paradigm), or though other methods such as event passing.
工具箱中避免链接时间的最大工具是适当的抽象级别。如果您的链接时间很长,可能是因为对象对其他对象了解太多。解耦它们是关键——通过抽象接口(可能使用 PIMPL 范例),或者通过其他方法,如事件传递。
The overhead for linking projects through Project Dependencies is also quite high. If your target platform is Win32 only, or primarily, you may consider using a header to link your dependent libraries via #pragma comment(lib, "pathToLib").
通过 Project Dependencies 链接项目的开销也相当高。如果您的目标平台仅是 Win32,或者主要是 Win32,您可以考虑使用标头通过 #pragma comment(lib, "pathToLib") 链接您的依赖库。
回答by Ben Schwehn
If you can live without the optimization, turn off link-time code generation (remove the /GL switch or in properties c/c++ -> Optimization -> Whole Program Optimization. For the linker remove /ltcg or use the Link Time Code Generation Setting). This will make the compiler slower though, as code generation now happens during compile time.
如果您可以不进行优化,请关闭链接时代码生成(删除 /GL 开关或在属性 c/c++ -> 优化 -> 整个程序优化中。对于链接器,删除 /ltcg 或使用链接时间代码生成设置)。但这会使编译器变慢,因为代码生成现在发生在编译时。
I've seen projects that take hours to build with /GL+/LTCG, mere seconds without (this one for example: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/750ed2b0-0d51-48a3-bd9a-e8f4b544ded8)
我见过使用 /GL+/LTCG 构建需要数小时的项目,没有的项目只需几秒钟(例如:http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/750ed2b0-0d51 -48a3-bd9a-e8f4b544ded8)
回答by peterchen
Have you considered improving hardware?
Do you use a separate physical hard drive for for the build? What kind of drives do you use?
您是否考虑过改进硬件?
您是否使用单独的物理硬盘驱动器进行构建?你使用什么样的驱动器?
As a general suggestion: throw in some memory, get a Velociraptor, put only sources and build directory there, measure again. If that helps, consider a RAID 0.
作为一般建议:放入一些内存,获取Velociraptor,仅在其中放置源和构建目录,然后再次测量。如果这有帮助,请考虑使用 RAID 0。
I've heard reports that upgrading from an XP core to an W2K3 core improved build times notably, presumably due to better memory management and caching.
我听说从 XP 核心升级到 W2K3 核心显着缩短了构建时间,大概是由于更好的内存管理和缓存。
As a suggestion for changing your code, you could move some functionality to a DLL, and link in parallel. But I'd not make such a change just to improve build times.
作为更改代码的建议,您可以将某些功能移动到 DLL,并并行链接。但我不会仅仅为了缩短构建时间而做出这样的改变。
回答by Greg Domjan
There are some general setting suggestions on Improving link time with IncrediBuild
有一些关于使用 IncrediBuild 改善链接时间的一般设置建议
You can also skip linking of static libs where you won't distribute them using IncrediLink
您还可以跳过不使用IncrediLink分发静态库的链接
We found that addition of a signing post build step would stop IncrediBuild from working on following projects, adding a comment to post build was supposed to help
我们发现添加签名后期构建步骤会阻止 IncrediBuild 处理以下项目,在后期构建中添加评论应该会有所帮助
rem IncrediBuild_AllowOverlap