使用boost库时加快编译/链接时 [英] Speed up compilation/link time when using boost libraries

查看:221
本文介绍了使用boost库时加快编译/链接时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用提升程序选项,这需要相当长的而(10秒或甚至更多)编译非常小的C ++ code。与它。它花费了1秒钟编译code,无Boost库。

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.

不知道如何提高编译/链接时使用Boost库?它是跨平台的,所以我需要编译code与Mac OS X / Linux的/ PC。

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.

推荐答案

是不是真的有什么可以做,超出了通常的招数:

There isn't really much you can do beyond the usual tricks:


  • 尽量减少依赖关系:拉只有你真正需要的Boost头文件,并用具体的头越好(许多库有一个主的头,如升压/ thread.hpp ,也与特定的头文件,如升压/线程/ shared_mutex.hpp ),
  • 子目录
  • 在可能情况下,依靠前锋声明,而不是包括整个头,

  • 如果可能的话,包括仅在的.cpp 文件头。如果包含在一个头,它拥有每一个翻译单元,包括该头编译时间进行编译。根据经验,一般情况下,尝试c您在头要尽量减少$ C $量,

  • 所有主要的编译器都支持precompiled头。使用这些削减编译时间,

  • 实验统一建立。这可能是也可能不是你的情况有优势。

  • minimize dependencies: pull in only the Boost headers you really need, and use as specific headers as possible (many libraries have a single "master" header, such as boost/thread.hpp, but also a subdirectory with specific headers, like boost/thread/shared_mutex.hpp),
  • where possible, rely on forward declarations instead of including the entire header,
  • if possible, include the header only in a .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,
  • all major compilers support precompiled headers. Use those to cut down compilation time,
  • experiment with unity builds. That may or may not be an advantage in your case.

和最后但并非最不重要的,最后的选择就是不使用这些特定的Boost库。

And last, but not least, a final option is just to not use those specific Boost libraries.

我有时用一定提振库初期,进出方便,如果/当编译时间变得太糟糕了,我开始寻找在该库是昂贵的编译,以及哪些可能通过相对简单的code被替换。通常情况下,升压被要求担保是如此一般。如果没有需要的东西,对8岁的编译器的工作原理,或者不必通过这么多不同类型的工作,那么你可以写一个简单的更换在为你工作,并采取几乎没有时间编译。

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.

这篇关于使用boost库时加快编译/链接时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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