Reputation: 125
I have trouble compiling a code which uses mongodb-cxx driver. Everything works fine with C driver but not Cxx. I run Fedora 28 and have already installed following packages from Fedors's official repositories:
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
The code I try to compile does not call any API function to connect to database, but as the first step, uses include files and namespaces needed to connect to a mongodb and run operations. The code I try to compile is:
#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;
}
I try to compile the code as below:
$ 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 ^~~~~~~~~~~~~~~~~~~~~~~
As said, I used Fedora's package manager to install monogdb's cxx driver and did not compile from the source. Is there any extra step that I need to do?
Thanks for your help,
D.
Upvotes: 1
Views: 424
Reputation: 12727
You are trying to mix the old C++ driver and the new. The package that you have installed, mongo-cxx-driver-devel-1.1.2-13.fc28.x86_64
is the end-of-life "legacy" C++ driver. It doesn't offer a pkg-config file.
Additionally, it appears that your code is attempting to include headers from both the old driver and the new mongocxx driver, which are completely separate projects.
Finally, you don't seem to have the required boost headers installed.
So, what you need to do is:
bsoncxx
or mongocxx
.bsoncxx
and mongocxx
headers. You will need to install the boost development headers and libraries, and stop trying to invoke pkg-config, which is only used when finding the new C++ driver.Upvotes: 1