在Windows上编译Mongo DB客户端示例时,链接器错误

Linker error while compiling mongo db client example on Windows

本文关键字:链接 错误 客户端 Windows 编译 Mongo DB      更新时间:2023-10-16

我在Windows上编译Mongo DB客户端示例时有一个链接问题。我正在使用Visual Studio2012。

我正在尝试编译Mongo git中的Src Mongo Mongo client examples clienttest.cpp。

我做了以下步骤:

  • 使用BJAM2构建了Boost V1.51。我在另一个项目上使用它,所以我知道二进制文件很好。
  • 构建Mongodb C 驱动程序为scons --dd mongoclient.lib
  • 包括boost包括在我的项目中的目录,包括目录。
  • 定义_crt_secure_no_warnings,以避免使用strncpy和of mongodb客户端代码的警告。
  • 包括该项目的提升(二进制)库目录。

仍然,我有以下错误

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 ::〜线程(void)的错误。看起来它强迫链接到链接到线程的lib二进制。

不幸的是,用<boost/filesystem.hpp>重复此技巧没有帮助:(

我还确保使用dumpbin.exe的32位目标编辑了所有LIB文件。

还可以是什么?

谢谢!

看起来我的消息给mongo-dev邮件列表没有到达目的地。也许已经过时了。

,但我设法通过有点骇人听闻的解决方案使其正常工作,因为我以前从未使用过SCONS。

核心的核心是,Mongo已预先融合了Boost 1.49,并且我的系统中安装了1.51。我试图针对Boost 1.51编译样品,而Mongo则用1.49编译了某些类别/方法的不匹配。

我通过调用

构建库

scons -j4 --dd --use-system-boost mongoclient.lib

也修改了SConstruct脚本。查找线elif "win32" == os.sys.platform:。在本节中,我添加了

env.Append( EXTRACPPPATH=[ "C:/work/externals/boost_1_51_0" ] )

指定其他"系统"文件夹。

我也必须禁用看起来像

的增强二进制库的存在
    for b in boostLibs:
        l = "boost_" + b
        if not conf.CheckLib([ l + boostCompiler + "-mt" + boostVersion,
                               l + boostCompiler + boostVersion ], language='C++' ):
            Exit(1)

因为我的库的命名是非常不同的。

当然,当使用MSVC库动态编译Boost时,它不涵盖情况。

我希望Mongo团队或一个了解SCONS的人会将构建脚本修改为

  • 允许指定系统Boost Library的路径
  • 允许MSVC的动态链接库

Mac OS

的解决方案

我知道这不是发布 Mac OS 的答案的地方。但是,我挣扎了几天,解决了麦格索的链接错误,终于使它起作用了...

mmacosx-version-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

编译并产生第二个