我刚刚在Windows上使用MSVC重建了boost 1.57,因为我想添加对zlib的支持:
.\b2 toolset=msvc-12.0 link=shared threading=multi address-model=64 --build-type=complete install -s NO_ZLIB=0 -s ZLIB_SOURCE=D:\zlib128
这样可以很好地构建并生成新文件boost_zlib-vc120-mt-1_57.dll
和boost_zlib-vc120-mt-1_57.lib
。
然后我使用cmake为我的项目添加提升:
FIND_PACKAGE(Boost ${BOOST_VERSION} EXACT REQUIRED COMPONENTS system date_time filesystem iostreams regex thread zlib)
if(Boost_FOUND)
ADD_DEFINITIONS(${BOOST_DEFINITIONS} -DBOOST_ALL_NO_LIB)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
TARGET_LINK_LIBRARIES(foobar ${Boost_LIBRARIES})
endif()
在Visual Studio中,我在“附加依赖项”中看到boost_zlib-vc120-mt-1_57.lib
现在也列在那里。但是尝试编译this example失败并出现链接器错误:
错误1730错误LNK2019:未解析的外部符号“int const boost :: iostreams :: zlib :: default_compression”(?default_compression @ zlib @ iostreams @ boost @@ 3HB)在函数“public:__cdecl boost :: iostreams中引用: :detail :: zlib_decompressor_impl> :: zlib_decompressor_impl>(int)“(?? 0?$ zlib_decompressor_impl @ V?$ allocator @ D @ std @@@ detail @ iostreams @ boost @@ QEAA @ H @ Z)
我该如何解决这个问题?