当我们程序中用到 boost 库时,链接的时候,有时出现这个错误:
error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: int __cdecl boost::iostreams::zlib_error::error(void)const " (__imp_?error@zlib_error@iostreams@boost@@QEBAHXZ),该符号在函数 "public: __cdecl boost::iostreams::gzip_error::gzip_error(class boost::iostreams::zlib_error const &)" (??0gzip_error@iostreams@boost@@QEAA@AEBVzlib_error@12@@Z) 中被引用
其原因是, boost 生成的是静态库,而自己的程序中,用的是动态链接到boost库,所以出现找不到库的错误。
解决办法:
把link的方式改成静态链接,例如把宏定义的 BOOST_ALL_DYN_LINK 去掉。
BOOST_ALL_DYN_LINK: 使用动态链接库的方式来link
BOOST_ALL_NO_LIB: 使用静态链接库的方式来link