Boost所说的“仅标头库"是什么意思?和“自动链接"? [英] What does Boost mean by "header-only libraries" and "automatic linking"?

查看:126
本文介绍了Boost所说的“仅标头库"是什么意思?和“自动链接"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Boost库文档页上,有两个类别,分别为"仅标头库"和"自动链接".

On the Boost library documentation page, there are two categories named "Header Only Libraries" and "Automatic Linking".

我想仅标头库" 意味着您不必链接到表示您必须链接.

I suppose "Header Only Libraries" means you don't have to link against Boost libraries in order to use them, and "Automatic Linking" means you have to link.

但是当我使用Boost.Timer时,我必须链接名为timer的静态或动态库(libboost_timer.alibboost_timer.so.1.48.0以及Linux库路径下指向这些库的各种软链接),这显然是准确的库Boost.Timer的文件.我什至需要链接Boost.SystemBoost.Chrono,尽管可以理解的是,库本身使用了一些其他需要链接的库.

But when I use Boost.Timer, I have to link a static or dynamic library named timer (libboost_timer.a and libboost_timer.so.1.48.0 and various soft links to these under Linux library path), which is apparently the exact library file of Boost.Timer. I even need to link against Boost.System and Boost.Chrono, though it is understandable that the library itself uses some other libraries that need to be linked.

另一方面,Boost明确指出Boost.Asio属于自动链接" ,但是没有任何库文件,其名称类似于asio.

On the other side, Boost has clearly stated that Boost.Asio belongs to "Automatic Linking", but there aren't any library files named anything like asio.

那么成为"仅标头库"或"自动链接"到底意味着什么?还是纯粹是一个错误?

So what does it actually mean to be a "header-only library" or "automatic linking"? Or is it purely a mistake?

推荐答案

正如您所说,仅标头库"表示整个库都在标头文件中,因此只需一行(或几行)#include行即可使用它.无需链接.

As you said, "Header only library" means that the whole library is in header files, so one (or several) #include lines is enough to use it. No linking is necessary.

自动链接"表示,尽管库需要进行某些链接(直接或作为依赖项),但您无需在编译器行中指定它,因为#include的文件将起到一些神奇作用.如果编译器支持,则自动引入适当的库.

"Automatic linking" means that, although the library needs some linking (either directly or as a dependency), you don't need to specify it in the compiler line, because the #include'd files will do some magic to bring in the appropriate libraries automatically, if supported by the compiler.

例如,在 MSVC 编译器中,它们使用#pragman comment(lib, "...");在Borland编译器中,他们使用#pragma defineoptions;等

For example, in MSVC compilers, they use #pragman comment(lib, "..."); in Borland compilers they use #pragma defineoptions;, etc.

最值得注意的是,GNU编译器不支持自动链接".

And most notably, "automatic linking" is not supported by the GNU compiler.

自动链接有时会很麻烦(例如,混合使用调试版本和发行版),并且您可以通过定义一些预处理器宏来选择性地禁用它们:BOOST_<libname>_NO_LIB.在这种情况下,您将必须手动进行链接.

Automatic linking can be troublesome sometimes (for example, mixing debug and release versions), and you can selectively disable them by defining some preprocessor macros: BOOST_<libname>_NO_LIB. In that case you will have to do the linking manually.

更新:关于下面的评论:

Boost.Timer声称是仅标头库",但它在lib目录中具有lib文件.

Boost.Timer claims to be a "Header only library" but it has lib files in the lib directory.

Boost文档中似乎有错误.实际上,有两个名为 timer 的不同库:旧的,已弃用的仅标头的

It looks like there is an error in the Boost documentation. Actually there are two different libraries named timer: The old, deprecated, header-only <boost/timer.hpp> and the new, improved, cooler, automatically linkable <boost/timer/timer.hpp>.

但是由于某些原因,主文档页面列出了旧文档的属性.

But for some reason, the main documentation page lists the properties of the old one.

没有Boost.Asio个lib文件.

在Boost主库文档页面库文档页面中,您可以看到由于相关性,Asio被列为自动链接.在其他地方中列出了特定的依赖项:Boost .System和Boost.Regex,并且都提供自动链接.

In the main Boost library documentation page library documentation page, you can see that Asio is listed as Automatic linking due to dependency. The specific dependencies are listed elsewhere: Boost.System and Boost.Regex, and both present automatic linking.

这篇关于Boost所说的“仅标头库"是什么意思?和“自动链接"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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