关于Auto-linking

以下讨论的环境基于Visual Studio 2010。

在使用OpenCV的过程中,我们不但要指定头文件和库的目录,而且要指定库的名称,比如为了使用常用的基本功能,我们需要指定附加libopencv_highgui249.dll。

相比之下,在使用C++的boost库的过程中,我们只需要指定头文件的目录和库目录,并不需要指定附加的依赖项(即指定的库的名称)。如果我们包含了boost/timer/timer.hpp这个头文件,同时使用/MD编译选项的话,boost会自动地给我们链接上libboost_date_time-vc100-mt-1_57.lib。这个过程就叫auto-linking。

 

在维基百科中,关于auto-linking是这么说的:

 Auto-linking is a mechanism for automatically determining which libraries to link to while building a C, C++ or Obj-C program. It is activated by means of #pragma comment(lib, <name>)statements in the header files of the library, or @import <name> depending on the compiler.

Most Windows compilers support auto-linking, as does Clang, while GCC does not support auto-linking [1]

大多数的Windows编译器支持auto-linking,而gcc不支持auto-linking。所以在gcc的环境中,我们大概要自己指定附加的依赖项(库名称)了。

 

在boost的文档中,我们可以找到关于auto-linking的一段说明:

Auto-Linking

Most Windows compilers and linkers have so-called “auto-linking support,” which eliminates the second challenge. Special code in Boost header files detects your compiler options and uses that information to encode the name of the correct library into your object files; the linker selects the library with that name from the directories you've told it to search.

The GCC toolchains (Cygwin and MinGW) are notable exceptions; GCC users should refer to thelinking instructions for Unix variant OSes for the appropriate command-line options to use.

这里的the second challenge意思是指定库名称的任务。

由于在boost的头文件中有special code(我想大概就是一些#pragma comment(lib, <name>)之类的声明),我们就无需自己指定库的名称,linker会自己在我们指定的库目录中寻找。

当然这里也说了,gcc的工具链是个notable exceptions。

 

转载于:https://www.cnblogs.com/nipan/p/4192445.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值