无法将MongoDB C驱动程序与MSVC一起使用来构建项目

Can't build project using mongodb c++ driver with MSVC

我正在尝试使用Visual Studio构建以下示例c代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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;
    }
}

我的代码没有收到任何错误,但是在构建过程中出现了以下错误:
enter


通过将" __STDC_LIMIT_MACROS "行添加到Project Properties \\\\\\\\ C / C \\\\\\\\ Preprocessor \\\\\\\\ Preprocessor Definitions中,消除了计时和比率错误。 (感谢@xdg的帮助)

对于其他mongocxx错误,问题是:
1.我试图使用64位BOOST库构建一个32位项目
通过创建一个新的64位项目来解决此问题
2.必须在项目属性\\\\\\\\ Linker \\\\\\\\\\ Input \\\\\\\\ Additional Dependencies

中包含bsoncxx.lib和mongocxx.lib文件

完成这些步骤后,项目构建成功,但是由于缺少bsoncxx,mongocxx,libmongoc-1.0和libbson-1.0 dll而导致运行时出错,我只需将上述dll复制到项目发行版中即可解决此问题。文件夹。