码迷,mamicode.com
首页 > 其他好文 > 详细

关于Auto-linking

时间:2014-12-29 22:48:55      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

以下讨论的环境基于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。

 

关于Auto-linking

标签:

原文地址:http://www.cnblogs.com/nipan/p/4192445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!