Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Windows上编译mongo db客户端示例时发生链接器错误_C++_Visual Studio_Mongodb_Boost - Fatal编程技术网

C++ 在Windows上编译mongo db客户端示例时发生链接器错误

C++ 在Windows上编译mongo db客户端示例时发生链接器错误,c++,visual-studio,mongodb,boost,C++,Visual Studio,Mongodb,Boost,在Windows上编译mongo db客户端示例时,我遇到了一个链接器问题。我正在使用Visual Studio 2012 我试图从mongo的git编译 我采取了以下步骤: 使用bjam2构建Boost v1.51。我正在另一个项目中使用它,所以我知道二进制文件很好 构建的MangGDB C++驱动程序为代码> sCONS——DD MangoCclipse 在我的项目中包含boostinclude目录作为附加的include目录 定义_CRT_SECURE_NO_警告,以避免MongoDB客

在Windows上编译mongo db客户端示例时,我遇到了一个链接器问题。我正在使用Visual Studio 2012

我试图从mongo的git编译

我采取了以下步骤:

  • 使用bjam2构建Boost v1.51。我正在另一个项目中使用它,所以我知道二进制文件很好
  • 构建的MangGDB C++驱动程序为代码> sCONS——DD MangoCclipse
  • 在我的项目中包含boostinclude目录作为附加的include目录
  • 定义_CRT_SECURE_NO_警告,以避免MongoDB客户端代码对strncpy等的使用发出警告
  • 将boost(binary)libraries目录包括到项目中
尽管如此,我还是发现了以下错误

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::thread _thrd(&Func);
_thrd.join();
在clientTest.cpp的开始部分,它帮助消除了有关缺少boost::thread::~thread(void)的错误。看起来它迫使链接器链接到线程的lib二进制文件

不幸的是,用
重复这个技巧没有帮助:(

我还知道Boost和Mongo client的所有LIB文件都是使用
dumpbin.exe
为32位目标编译的

伙计们,还能是什么


谢谢!

看来我发送给mongo dev邮件列表的邮件没有到达目的地。可能是预建模的

但我设法通过一个有点黑客的解决方案使它工作,因为我以前从未使用过烤饼

问题的核心是mongo与Boost 1.49预绑定,我的系统中安装了Boost 1.51。我试图针对Boost 1.51编译示例,而mongo是使用1.49编译的,因此某些类/方法不匹配

我打电话建了图书馆

scons-j4-dd-使用系统boost mongoclient.lib

我还修改了
SConstruct
脚本。查找行
elif“win32”==os.sys.platform:
。在本节中,我添加了

env.Append(EXTRACPPPATH=[“C:/work/externals/boost\u 1\u 51\u 0”)

指定其他“系统”文件夹

我还必须禁用boost二进制库的存在性检查

    for b in boostLibs:
        l = "boost_" + b
        if not conf.CheckLib([ l + boostCompiler + "-mt" + boostVersion,
                               l + boostCompiler + boostVersion ], language='C++' ):
            Exit(1)
因为我的库的命名非常不同

当然,它不包括boost是用MSVC库动态编译的情况

我希望Mongo团队或熟悉Scons的人将修改构建脚本以

  • 允许指定系统boost库的路径
  • 允许为MSVC构建动态链接库

    • 适用于Mac OS的解决方案

      我知道这不是一个发布Mac OS答案的地方。但是,我为解决msgasserted链接器错误苦苦挣扎了几天,终于让它工作了

      应将mmacosx版本min=10.5添加到命令行

      g++ -m64 -I/Users/accessmac/mgoclient/include -L/Users/accessmac/mgoclient/lib second.cpp -lboost_system-mt -lboost_program_options-mt -lboost_filesystem-mt -lboost_thread-mt -lmongoclient  -mmacosx-version-min=10.5 -o second
      
      编译并生成第二个

      g++ -m64 -I/Users/accessmac/mgoclient/include -L/Users/accessmac/mgoclient/lib second.cpp -lboost_system-mt -lboost_program_options-mt -lboost_filesystem-mt -lboost_thread-mt -lmongoclient  -mmacosx-version-min=10.5 -o second