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; } } |
我的代码没有收到任何错误,但是在构建过程中出现了以下错误:
我已经按照以下步骤构建了驱动程序:
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
此外,我在项目中添加了以下包含库:
-bsoncxx
-mongocxx
-libmongoc
-libbson
-促进
以及以下链接器库:
-boost 64位库
-mongo驱动程序库
如果有人能告诉我我的构建有什么问题,将不胜感激。
通过将" __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复制到项目发行版中即可解决此问题。文件夹。