boost库的编译方法在网上很容易找到,这篇文章的主要内容是编译后在实际运用过程中出现链接库失败的解决办法,例如在运用thread库时出现 的:LINK : fatal error LNK1104: 无法打开文件“libboost_date_time-vc71-mt-sgd-1_39.lib”错误。
要解决问题,首先要弄明白问题出错的原因。
下面我简要介绍boost库生成的.lib文件的命名规则。
以 libboost_thread-vc71-mt-sgd-1_39.lib为例:
-
lib
- Prefix : 除了Microsoft Windows操作系统, 每一个Boost库都以lib为开始。在Windows下, 只有静态库使用 lib 开始. boost_thread
- 库名 : 所有Boost库都以 boost_为库名 . -vc71
- Toolset tag : 表示编译二进制的工具的名称和版本号. -mt
- Threading tag : 标明该库支持多线程。 -sgd
-
ABI tag : encodes details that affect the library's interoperability with other compiled code. For each such feature, a single letter is added to the tag:
Key Use this library when: s linking statically to the C++ standard library and compiler runtime support libraries. g using debug versions of the standard and runtime support libraries. y using a special debug build of Python . d building a debug version of your code.5 p using the STLPort standard library rather than the default one supplied with your compiler. n using STLPort's deprecated “native iostreams” feature.6
要编译boost库,需要运行bjam时后面带有参数,如果想生成上面例子格式的.lib文件,就可以在运行bjam文件时带上以下参数:
- bjam --toolset=msvc-7.1 link=static runtime-link=static --threading=multi --with-thread stage debug release 现在简要介绍一下bjam各参数的意义 : --toolset:编译器的版本,如果你用的是vs2003 后面就要带参数 msvc-7.1
-
link: 注意,前面没有“--”, 决定使用静态库还是动态库。这个参数对应 libboost_thread-vc71-mt-sgd-1_39.lib 中的 -s
runtime-link: 决定是静态还是动态链接C/C++标准库.
-
其他几个参数我就不在详述,下面附上bjam参数表,大家可以在里面找到详细的参数。
bjam参数 --build-dir= <builddir> 编译的临时文件会放在builddir里(这样比较好管理,编译完就可以把它删除了) --stagedir= <stagedir> 存放编译后库文件的路径,默认是stage --build-type= complete 编译所有版本,不然只会编译一小部分版本(确切地说是相当于:variant=release, threading=multi;link=shared|static;runtime-link=shared) variant= debug|release 决定编译什么版本(Debug or Release?) link= static|shared 决定使用静态库还是动态库。 threading= single|multi 决定使用单线程还是多线程库。 runtime-link= static|shared 决定是静态还是动态链接C/C++标准库。 --with- <library> 只编译指定的库,如输入--with-regex就只编译regex库了。 --show- libraries 显示需要编译的库名称
其实出现库文件没法打开的主要原因是在编译boost库时,运行bjam文件时参数没有输入正确,只要按照上面两个表里的参数详细对照一下,选用正确的参数,这个问题一定会解决的。呵呵,当然了,在vs环境中不要忘记包含库文件目录吆!
参考:http://blog.youkuaiyun.com/FeelinArt/archive/2008/07/18/2669293.aspx
http://www.cppprog.com/2009/0112/48.html
当使用boost库,特别是thread库时遇到'LINK : fatal error LNK1104: 无法打开文件...lib'的错误,本文提供解决方案。问题根源在于编译boost库时bjam参数不正确。理解lib文件命名规则,如libboost_thread-vc71-mt-sgd-1_39.lib,并确保编译参数匹配,同时在VS中添加库文件路径,即可解决此问题。
1985

被折叠的 条评论
为什么被折叠?



