【问题标题】:MongoDB C++ Driver - Unresolved External SymbolMongoDB C++ 驱动程序 - 未解析的外部符号
【发布时间】:2014-03-05 06:05:21
【问题描述】:

我正在尝试运行 MongoDB C++ 驱动程序的示例程序,以便我可以运行一些测试,但遇到了一些我卡住的错误。

Error   1   error LNK2019: unresolved external symbol "__declspec(dllimport)     public: __thiscall mongo::DBClientConnection::DBClientConnection(bool,class     mongo::DBClientReplicaSet *,double)" (__imp_??0DBClientConnection@mongo@@QAE@_NPAVDBClientReplicaSet@1@N@Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ)  E:\Programming\C++\BoostTest\BoostTest\BoostTest\Testcpp.obj    BoostTest

Error   2   error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall mongo::DBClientConnection::~DBClientConnection(void)" (__imp_??1DBClientConnection@mongo@@UAE@XZ) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) E:\Programming\C++\BoostTest\BoostTest\BoostTest\Testcpp.obj    BoostTest

Error   3   error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall mongo::DBClientConnection::connect(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?connect@DBClientConnection@mongo@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ)   E:\Programming\C++\BoostTest\BoostTest\BoostTest\Testcpp.obj    BoostTest

这是代码

#include <cstdlib>
#include <iostream>
#include "mongo\client\dbclient.h"

#define BOOST_ALL_DYN_LINK

void run()
{
    mongo::DBClientConnection c;
    c.connect("localhost");
}

int main()
{
    try
    {
        run();
        std::cout << "Connected" << std::endl;
    }
    catch(const mongo::DBException &e)
    {
        std::cout << "caught " << e.what() << std::endl;
    }
    return EXIT_SUCCESS;
}

在任何人问之前,我已经引用了 Boost 库和标题,它们似乎工作正常。我还引用了 Mongo 库和标头。

Additional Include Directories: Boost and Mongo Source

Linker Additional Library Directories: boost/stage/lib and Mongo build client

谁有线索?我是否必须在附加依赖项中包含 dbclient.obj 文件?当我这样做时,我会收到 96 个新错误。我想我可能遗漏了一些 .dll,但不知道是什么。

感谢任何帮助,因为这只是一个更大项目的一小部分。

【问题讨论】:

    标签: c++ mongodb unresolved-external mongo-c-driver


    【解决方案1】:

    试试:

    1. 32 与 64 位不匹配。
    2. 在针对旧库使用 MS VC 编译器时,我遇到了类似的问题。解决方案是获取最新的库。

    【讨论】:

      【解决方案2】:

      我的成功案例是:MS Visual Studio 2015 + mongo-cxx-driver-26compat(构建为 32 位 DLL)+来自 boost_1_59_0 的 32 位 DLL。

      【讨论】:

        猜你喜欢
        • 2013-10-05
        • 2013-02-28
        • 2012-11-19
        • 1970-01-01
        • 2012-12-17
        • 2012-06-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多