在eclipse链接器mongocxx bsoncxx libs中安装并添加之后, 尝试编译代码
#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;
}
}
有错误
g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/MongoCxx.d" -MT"src/MongoCxx.o" -o "src/MongoCxx.o" "../src
/MongoCxx.cpp"
../src/MongoCxx.cpp:8:9: warning: #pragma once in main file [enabled by default]
#pragma once
^
../src/MongoCxx.cpp:13:31: fatal error: mongocxx/client.hpp: No such file or directory
src/subdir.mk:18: recipe for target 'src/MongoCxx.o' failed
#include <mongocxx/client.hpp>
^
我可能做错了 在官方页面我按照指示如何安装 https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(New-Driver)
我使用eclipse和OS OpenSuse