无法将MongoDB C ++驱动程序与MSVC一起使用来构建项目 [英] Can't build project using mongodb c++ driver with MSVC
问题描述
我正在尝试使用Visual Studio构建以下示例c ++代码:
I'm trying to build the following sample c++ code with Visual Studio:
#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;
}
}
我的代码没有收到任何错误,但是在构建过程中出现了以下错误:
I'm not getting any errors with the code, but during building I'm getting the following errors:
我已经根据以下内容构建了驱动程序: https://github.com/mongodb/mongo-cxx-driver/blob/master/appveyor.yml
I've built the the driver according to this: https://github.com/mongodb/mongo-cxx-driver/blob/master/appveyor.yml
系统信息:-Win10-Visual Studio Community 2015更新3-使用Boost 1.60.0 64位-使用CMake 3.7.0-使用Git 2.10.2
System info: -Win10 -Visual Studio Community 2015 Update 3 -using Boost 1.60.0 64-bit -using CMake 3.7.0 -using Git 2.10.2
此外,我还向项目添加了以下包含库:-bsoncxx-mongocxx-libmongoc-libbson-促进以及以下链接器库:-boost 64位库-mongo驱动程序库
Also, I have added the following include libraries to the project: -bsoncxx -mongocxx -libmongoc -libbson -boost And the following linker libraries: -boost 64-bit lib -mongo driver libraries
如果有人能告诉我我的构建有什么问题,将不胜感激.
If anyone could tell me what's wrong with my build it would be much appreciated.
推荐答案
通过在Project Properties \ C/C ++ \ Preprocessor \ Preprocessor定义中添加"__STDC_LIMIT_MACROS"行,消除了计时和比率错误.(感谢@xdg的帮助)
Got rid of the chrono and ratio errors by adding the " __STDC_LIMIT_MACROS " line to Project Properties\C/C++\Preprocessor\Preprocessor Definitions. (thanks @xdg for the help)
对于其他mongocxx错误,问题是:1.我试图使用64位BOOST库构建一个32位项目通过创建一个新的64位项目来解决此问题2.必须将bsoncxx.lib和mongocxx.lib文件包含在Project Properties \ Linker \ Input \ Additional Dependencies
For the other mongocxx errors, the problems were: 1. I was trying to build a 32-bit project using 64-bit BOOST libraries -got this fixed by creating a new 64-bit project 2. had to include the bsoncxx.lib and mongocxx.lib files in Project Properties\Linker\Input\Additional Dependencies
完成这些步骤后,项目构建成功,但是由于缺少bsoncxx,mongocxx,libmongoc-1.0和libbson-1.0 dll而导致运行时出错,我只需将上述dll复制到项目发行版中即可解决此问题.文件夹.
After these steps the project build was successful, but I got errors during runtime because the bsoncxx, mongocxx, libmongoc-1.0 and libbson-1.0 dlls were missing, I got that fixed simply by copying the above mentioned dlls to the project release folder.
这篇关于无法将MongoDB C ++驱动程序与MSVC一起使用来构建项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!