Reputation: 1
Installed mongocxx driver version 3.10.1 on linux using tarball from github(also installed mongo-c driver version 1.27.5).
For installation i used below commands for mongo-c driver:
tar -xzf mongo-c-driver.tar.gz
cd mongo-c-driver-1.27.5/
mkdir cmake-build
cd cmake-build/
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_MONGODB_AWS_AUTH=OFF -DOPENSSL_ROOT_DIR=/usr/bin/openssl ..
make
sudo make install
And for the mongocxx driver used below commands:
tar -xzf mongo-cxx-driver-r3.10.1.tar.gz
cd mongo-cxx-driver-r3.10.1/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DMONGOCXX_OVERRIDE_DEFAULT_INSTALL_PREFIX=OFF -DBSONCXX_POLY_USE_BOOST=1
cmake --build .
sudo cmake --build . --target install
I use it with qt c++ development with mongodb. But after including the mongocxx and bsoncxx .hpp files i get
parse error at /.../include/bsoncxx/v_noabi/bsoncxx/enums/binary_sub_type.hpp types.hp 68
on qt creator. Also says in the detail of the error:
File not found /local/include/bsoncxx/v_noabi/bsoncxx/types.hp
yes not ".hpp" it says "types.hp" . I get this while building my application. I can see the included .hpp source files of mongocxx and bsoncxx from my .cpp code. Library paths and includings also made on the .pro file of the project as below. Not getting any error from it.
INCLUDEPATH += /usr/local/include/mongocxx/v_noabi \
/usr/local/include/bsoncxx/v_noabi
LIBS += -L/usr/local/lib64 -lmongocxx -lbsoncxx
And i included below classes:
mongocxx/client.hpp
mongocxx/uri.hpp
mongocxx/instance.hpp
mongocxx/database.hpp
mongocxx/collection.hpp
bsoncxx/builder/stream/document.hpp
How can i resolve this error?
Tried to build my qt c++ application and got this error from qt creator.
Upvotes: 0
Views: 85
Reputation: 8310
In the official documentation first they recommend to use pkg-config to get all the correct compilation flags. Check the output of
pkg-config --cflags --libs libmongocxx
most likely there are more required include directories (on my Ubuntu there is also /usr/local/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc
).
Now to use the output of pkg-config
with your Qt Creator you don't need to copy-paste these flags in your *.pro
file, instead use this:
SOURCES += main.cpp
CONFIG += link_pkgconfig
PKGCONFIG += libmongocxx
TARGET = hello
It will allow you to compile simple hello world including mongocxx headers:
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/database.hpp>
#include <mongocxx/collection.hpp>
#include <bsoncxx/builder/stream/document.hpp>
int main() {
return 0;
}
Upvotes: 1