无法针对 Fedora 中的 mongo C++ 驱动程序进行编译
Cannot compile against the mongo C++ driver in Fedora
我在编译使用 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)
Package libmongocxx was not found in the pkg-config search path.
Perhaps you should add the directory containing `libmongocxx.pc' to
the PKG_CONFIG_PATH environment variable Package 'libmongocxx',
required by 'virtual:world', not found In file included from
/usr/include/mongo/db/json.h:20,
from mongo-cxx.cc:4: /usr/include/mongo/bson/bsonobj.h:20:10: fatal error:
boost/noncopyable.hpp: No such file or directory #include
^~~~~~~~~~~~~~~~~~~~~~~
如前所述,我使用Fedora的包管理器安装了monogdb的cxx驱动程序,并没有从源代码编译。我需要做任何额外的步骤吗?
感谢您的帮助,
D.
您正在尝试混合旧的 C++ driver 和新的。您安装的软件包 mongo-cxx-driver-devel-1.1.2-13.fc28.x86_64
是 end-of-life "legacy" C++ driver。它不提供 pkg-config 文件。
此外,您的代码似乎正试图包含来自旧 driver 和新 mongocxx driver 的 headers,它们是完全独立的项目。
最后,您似乎没有安装所需的提升 headers。
所以,您需要做的是:
- 了解您是否可以获得用于 fedora 的新 C++ driver 的软件包。如果是这样,请卸载旧的 driver 包,安装新的 C++ driver 包,并删除不以
bsoncxx
或 [=12 开头的 headers =].
- 如果您无法获得新的 C++ driver,则需要使用旧版,并且您应该停止使用
bsoncxx
和 mongocxx
headers。您将需要安装 boost 开发 headers 和库,并停止尝试调用 pkg-config,它仅在找到新的 C++ driver. 时使用
我在编译使用 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)
Package libmongocxx was not found in the pkg-config search path. Perhaps you should add the directory containing `libmongocxx.pc' to the PKG_CONFIG_PATH environment variable Package 'libmongocxx', required by 'virtual:world', not found In file included from /usr/include/mongo/db/json.h:20, from mongo-cxx.cc:4: /usr/include/mongo/bson/bsonobj.h:20:10: fatal error: boost/noncopyable.hpp: No such file or directory #include ^~~~~~~~~~~~~~~~~~~~~~~
如前所述,我使用Fedora的包管理器安装了monogdb的cxx驱动程序,并没有从源代码编译。我需要做任何额外的步骤吗?
感谢您的帮助,
D.
您正在尝试混合旧的 C++ driver 和新的。您安装的软件包 mongo-cxx-driver-devel-1.1.2-13.fc28.x86_64
是 end-of-life "legacy" C++ driver。它不提供 pkg-config 文件。
此外,您的代码似乎正试图包含来自旧 driver 和新 mongocxx driver 的 headers,它们是完全独立的项目。
最后,您似乎没有安装所需的提升 headers。
所以,您需要做的是:
- 了解您是否可以获得用于 fedora 的新 C++ driver 的软件包。如果是这样,请卸载旧的 driver 包,安装新的 C++ driver 包,并删除不以
bsoncxx
或 [=12 开头的 headers =]. - 如果您无法获得新的 C++ driver,则需要使用旧版,并且您应该停止使用
bsoncxx
和mongocxx
headers。您将需要安装 boost 开发 headers 和库,并停止尝试调用 pkg-config,它仅在找到新的 C++ driver. 时使用