【问题标题】:Can't build project using mongodb c++ driver with MSVC无法使用带有 MSVC 的 mongodb c++ 驱动程序构建项目
【发布时间】:2016-11-17 16:02:07
【问题描述】:

我正在尝试使用 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;
    }
}

我没有收到任何代码错误,但在构建过程中我收到以下错误:

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

系统信息: -Win10 -Visual Studio 社区 2015 更新 3 - 使用 Boost 1.60.0 64 位 - 使用 CMake 3.7.0 - 使用 Git 2.10.2

另外,我在项目中添加了以下包含库: -bsoncxx -mongocxx -libmongoc -利布森 -促进 以及以下链接器库: - 提升 64 位库 -mongo 驱动程序库

如果有人能告诉我我的构建出了什么问题,将不胜感激。

【问题讨论】:

  • 您正在构建哪个版本的 mongocxx?
  • github的最新版本,我认为是3.0.3版。
  • 这看起来像是一个 MSVC 问题。例如,请参阅 this postthis Google search。一旦你得到正确的比率和计时构建,我怀疑 mongocxx 位会起作用。
  • 太棒了,第一个链接帮助解决了这个问题,谢谢!

标签: c++ mongodb boost


【解决方案1】:

通过将“__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 复制到项目版本即可修复文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 2011-11-19
    • 1970-01-01
    相关资源
    最近更新 更多