【发布时间】:2012-10-30 21:35:02
【问题描述】:
在 Windows 上编译 mongo db 客户端示例时遇到链接器问题。我正在使用 Visual Studio 2012。
我正在尝试从 mongo 的 git 编译 src\mongo\client\examples\clientTest.cpp。
我做了以下步骤:
- 使用 bjam2 构建 Boost v1.51。我在另一个项目中使用它,所以我知道二进制文件很好。
- 构建 MongoDB C++ 驱动程序为
scons --dd mongoclient.lib - 在我的项目中包含的 boost 包含目录作为附加包含目录。
- 定义 _CRT_SECURE_NO_WARNINGS 以避免 MongoDB 客户端代码在使用 strncpy 等时出现警告。
- 将 boost(二进制)库目录包含到项目中。
我仍然收到以下错误
1>mongoclient.lib(log.obj) : error LNK2019: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::convert(char const *,char const *,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &,class std::codecvt<wchar_t,char,int> const &)" (?convert@path_traits@filesystem3@boost@@YAXPBD0AAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@ABV?$codecvt@_WDH@5@@Z) referenced in function "void __cdecl boost::filesystem3::path_traits::dispatch<class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &,class std::codecvt<wchar_t,char,int> const &)" (??$dispatch@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@path_traits@filesystem3@boost@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@4@ABV?$codecvt@_WDH@4@@Z)
1>mongoclient.lib(log.obj) : error LNK2019: unresolved external symbol "private: static class std::codecvt<wchar_t,char,int> const * & __cdecl boost::filesystem3::path::wchar_t_codecvt_facet(void)" (?wchar_t_codecvt_facet@path@filesystem3@boost@@CAAAPBV?$codecvt@_WDH@std@@XZ) referenced in function "public: static class std::codecvt<wchar_t,char,int> const & __cdecl boost::filesystem3::path::codecvt(void)" (?codecvt@path@filesystem3@boost@@SAABV?$codecvt@_WDH@std@@XZ)
1>mongoclient.lib(log.obj) : error LNK2019: unresolved external symbol "class boost::filesystem3::file_status __cdecl boost::filesystem3::detail::status(class boost::filesystem3::path const &,class boost::system::error_code *)" (?status@detail@filesystem3@boost@@YA?AVfile_status@23@ABVpath@23@PAVerror_code@system@3@@Z) referenced in function "bool __cdecl boost::filesystem3::exists(class boost::filesystem3::path const &)" (?exists@filesystem3@boost@@YA_NABVpath@12@@Z)
1>mongoclient.lib(background.obj) : error LNK2019: unresolved external symbol "public: __thiscall boost::thread::~thread(void)" (??1thread@boost@@QAE@XZ) referenced in function "public: class mongo::BackgroundJob & __thiscall mongo::BackgroundJob::go(void)" (?go@BackgroundJob@mongo@@QAEAAV12@XZ)
所以看起来它忽略了 boost 标头中的 #pragma comment lib 指令。
我尝试在项目设置的Linker/Input 选项卡中明确添加libboost_thread-vc110-mt-sgd-1_51.lib。它没有帮助。
我尝试在示例的主 cpp 文件中指定 #pragma comment(lib, "libboost_thread-vc110-mt-sgd-1_51.lib")。它也没有帮助。
但是!添加
#include <boost/thread/thread.hpp>
和
boost::thread _thrd(&Func);
_thrd.join();
在 clientTest.cpp 的开头帮助消除了关于缺少 boost::thread::~thread(void) 的错误。看起来它强制链接器链接到线程的 lib 二进制文件。
不幸的是,用<boost/filesystem.hpp> 重复这个技巧没有帮助:(
我还 made sure 说,Boost 和 Mongo 客户端的所有 LIB 文件都是使用 dumpbin.exe 为 32 位目标编译的。
还有什么可能是伙计们?
谢谢!
【问题讨论】:
标签: c++ visual-studio mongodb boost