【发布时间】:2018-07-21 09:33:47
【问题描述】:
我无法编译使用 mongodb-cxx 驱动程序的代码。一切都适用于 C 驱动程序,但不适用于 Cxx。我运行 Fedora 28 并且已经从 Fedors 的官方存储库安装了以下软件包:
mongo-c-driver-1.9.5-1.fc28.x86_64 mongo-c-driver-devel-1.9.5-1.fc28.x86_64 mongo-c-driver-libs-1.9.5-1.fc28.x86_64 mongo-cxx-driver-1.1.2-13.fc28.x86_64 mongo-cxx-driver-devel-1.1.2-13.fc28.x86_64
我尝试编译的代码不调用任何 API 函数来连接数据库,但作为第一步,使用连接到 mongodb 和运行操作所需的包含文件和命名空间。我尝试编译的代码是:
#include <cstdint>
#include <iostream>
#include <vector>
#include <mongo/db/json.h>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::open_document;
int main() {
return 0;
}
我尝试编译如下代码:
$ c++ --std=c++11 mongo-cxx.cc -o test $(pkg-config --cflags --libs libmongocxx)
在 pkg-config 搜索路径中找不到包 libmongocxx。 也许您应该将包含“libmongocxx.pc”的目录添加到 PKG_CONFIG_PATH 环境变量包“libmongocxx”, 'virtual:world' 需要,在包含的文件中找不到 /usr/include/mongo/db/json.h:20, 来自 mongo-cxx.cc:4: /usr/include/mongo/bson/bsonobj.h:20:10: 致命错误: boost/noncopyable.hpp:没有这样的文件或目录#include ^~~~~~~~~~~~~~~~~~~~~~~
如前所述,我使用 Fedora 的包管理器安装 monogdb 的 cxx 驱动程序,并没有从源代码编译。我需要做任何额外的步骤吗?
感谢您的帮助,
D.
【问题讨论】:
标签: c++ mongodb mongo-cxx-driver