无法使用mongodb c ++驱动程序与MSVC

时间:2016-11-17 16:02:07

标签: c++ mongodb boost

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

#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 image description here

enter image description here

我根据这个建立了驱动程序: https://github.com/mongodb/mongo-cxx-driver/blob/master/appveyor.yml

系统信息: -Win10 -Visual Studio Community 2015 Update 3 - 使用64.6位Boost 1.60.0 - 使用CMake 3.7.0 - 使用Git 2.10.2

另外,我在项目中添加了以下include库: -bsoncxx -mongocxx -libmongoc -libbson -促进 以下链接库: - 增强64位lib -mongo驱动程序库

如果有人能告诉我构建的错误,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

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

对于其他mongocxx错误,问题是: 1.我试图使用64位BOOST库构建一个32位项目  通过创建一个新的64位项目来修复此问题 2.必须在Project Properties \ Linker \ Input \ Additional Dependencies中包含bsoncxx.lib和mongocxx.lib文件

在这些步骤之后,项目构建成功,但是我在运行时遇到错误,因为缺少bsoncxx,mongocxx,libmongoc-1.0和libbson-1.0 dll,我只是通过将上面提到的dll复制到项目发布中来解决这个问题文件夹中。

相关问题