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

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

问题描述

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

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

我想仅标题库" 意味着您不必链接到 Boost 库才能使用它们,自动链接" 意味着你必须链接.

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.a>libboost_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 属于 "Automatic Linking",但是没有任何类似 的库文件>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?

推荐答案

如你所说,Header only library"是指整个库都在头文件中,所以一个(或几个)#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'如果编译器支持,d 文件会自动引入适当的库.

"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 编译器中,他们使用 #实用评论(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__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 的不同库:旧的、已弃用的、仅标头的 <boost/timer.hpp> 和新的、改进的、更酷的、可自动链接的 <boost/timer/timer.hpp>.

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 库文件.

在主 Boost 库文档页面 库文档页面,你可以看到Asio 被列为由于依赖而自动链接.具体的依赖列在elsewhere: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天全站免登陆