使用 boost 库时加快编译/链接时间
我正在使用 Boost 程序选项,并且需要用它编译非常小的 C++ 代码需要相当长的时间(10 秒甚至更多)。在没有 boost 库的情况下编译代码花了 1 秒。
知道如何使用 boost 库来提高编译/链接时间吗?它是跨平台的,所以我需要在 Mac OS X/Linux/PC 上编译代码。
I'm using Boost Program Options, and it takes quite a while (10 seconds or even more) for compiling very small C++ code with it. It took 1 second compiling the code without boost library.
Any idea how to boost compilation/link time with boost library? It's cross platform, so I need to compile the code with Mac OS X/Linux/PC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了通常的技巧之外,您实际上无能为力:
boost/thread.hpp
,但也是具有特定标头的子目录,例如boost/thread/shared_mutex.hpp
),.cpp
文件中。如果将其包含在标头中,则每次编译包含该标头的翻译单元时都必须编译它。作为一般经验法则,请尽量减少标头中的代码量,最后但并非最不重要的一点是,最后一个选择是不使用那些特定的 Boost 库。
有时,出于方便,我会尽早使用某些 Boost 库,如果/当编译时间变得太糟糕时,我会开始查看哪些库的编译成本很高,哪些库可以用相对简单的代码替换。通常,Boost 会因过于笼统的要求而受到阻碍。如果您不需要在 8 年前的编译器上工作的东西,或者不需要跨这么多不同类型工作的东西,那么您也许可以编写一个适合您的简单替代品,并且几乎不需要时间来编译。
There isn't really much you can do beyond the usual tricks:
boost/thread.hpp
, but also a subdirectory with specific headers, likeboost/thread/shared_mutex.hpp
),.cpp
file. If you include it in a header, it has to be compiled every time a translation unit which includes that header is compiled. As a general rule of thumb, try to minimize the amount of code you have in headers,And last, but not least, a final option is just to not use those specific Boost libraries.
I sometimes use certain Boost libs early on, out of convenience, and if/when compilation time gets too bad, I start looking at which libraries are expensive to compile, and which ones could be replaced by relatively simple code. Often, Boost is encumbered by the requirement to be so general. If you don't need something that works on 8 year old compilers, or which doesn't have to work across quite so many different types, then you may be able to write a simple replacement which works for you, and takes almost no time to compile.
我使用编译器防火墙习惯用法来减少编译时间,取得了很好的成功。
I had good success with the compiler firewall idiom to reduce compile times.