C++ Windows LNK2001中的Mongocxx:未解析的外部符号\uuu imp\u mongoc\u read\u prefs\u new

C++ Windows LNK2001中的Mongocxx:未解析的外部符号\uuu imp\u mongoc\u read\u prefs\u new,c++,mongodb,mongo-c-driver,mongo-cxx-driver,C++,Mongodb,Mongo C Driver,Mongo Cxx Driver,我严格遵守了以下文件中的说明(包括构建mongo-c-driver的说明): 我正在尝试构建提供的示例代码(使用VS2015),为了方便起见,我将复制粘贴该代码: #include <iostream> #include <bsoncxx/builder/stream/document.hpp> #include <bsoncxx/json.hpp> #include <mongocxx/client.hpp> #include <mon

我严格遵守了以下文件中的说明(包括构建mongo-c-driver的说明):

我正在尝试构建提供的示例代码(使用VS2015),为了方便起见,我将复制粘贴该代码:

#include <iostream>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>

int main(int, char**) {
    mongocxx::instance inst{};
    mongocxx::client conn{ mongocxx::uri{} };

    bsoncxx::builder::stream::document document{};

    auto collection = conn["testdb"]["testcollection"];
    document << "hello" << "world";

    collection.insert_one(document.view());
    auto cursor = collection.find({});

    for (auto&& doc : cursor) {
        std::cout << bsoncxx::to_json(doc) << std::endl;
    }
}
它看起来好像是来自mongo c驱动程序。我已经看到了,但是我已经链接了上面提到的mongoc-static-1.0.lib——不幸的是,在这篇文章中没有什么其他内容。编译器显然正在查找所述库(否则它会抱怨“未找到”错误),因此我只能认为我以某种方式错误地构建了库

在这一点上,我还将提到,我已经成功地使用非静态libs和dll构建和运行了代码——但是,避免使用dll是非常可取的,因此如果可能的话,我希望使用静态libs

现在,我已经多次阅读安装说明,下面是一些突出的问题:

如果需要静态库,请确保在构建libmongoc时使用--enable static configure选项

然而,这似乎只适合在Linux中安装,我正在使用CMake在Windows中安装。我运行了CMake.exe-LH以查看有哪些可用选项,希望找到一些关于静态libs的信息,但没有骰子。似乎没有构建静态libs所需的选项,因为当我安装mongo-c-driver时,我成功地获得了bson-static-1.0.lib和mongoc-static-1.0 libs


我发现自己不知所措!非常感谢您的帮助,干杯。

您解决问题了吗?我也有类似的问题。但是,如果您使用较旧的驱动程序,如mongoc 1.4、bson 1.4和mongocxx 3.0,似乎没什么问题,尽管它们只能支持mongodb 3.2和更旧的

注意:这也已发布到mongodb用户邮件列表中,正在讨论:
libmongocxx.lib(distinct.obj) : error LNK2001: unresolved external symbol __imp_mongoc_read_prefs_new