Implement MongoDB with Qt: mongocxx
-
Hi,
I want to implement mongoDB with qt. I could not find a module for mongodb in qt so I went with: http://mongocxx.org/mongocxx-v3/installation/
I installed it and tested it with the command (on test.cpp provided in the link):c++ test.cpp -o test $(pkg-config --cflags --libs libmongocxx)
and
g++ test.cpp -o test -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi -L/usr/local/lib -lmongocxx -lbsoncxx
It compiled and ran successfully.
To add this to qt I found this https://forum.qt.io/topic/77841/qt-and-mongocxx-linker-error but using the solution there did not work for me.
Here is my .pro file (relevent part):#-I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi -L/usr/local/lib -lmongocxx -lbsoncxx # ^ ouput of: pkg-config --cflags --libs libmongocxx INCLUDEPATH += \ -I/usr/local/include/mongocxx/v_noabi \ -I/usr/local/include/bsoncxx/v_noabi LIBS += \ -L/usr/local/lib \ -lmongocxx \ -lbsoncxx
I am using arch linux if that makes a difference.
What am I missing here?
Thanks,
Arush -
Hi and welcome to devnet,
What error are you getting exactly ?
-
Hi,
I get file not found errors on these lines:#include <bsoncxx/json.hpp> #include <mongocxx/client.hpp> #include <mongocxx/stdx.hpp> #include <mongocxx/uri.hpp> #include <mongocxx/instance.hpp>
Thanks
-
@Arush-Gupta
This is not my area, so may not be correct, but while you wait for an expert to comment....-I/usr/local/include/mongocxx/v_noabi \ -I/usr/local/include/bsoncxx/v_noabi
This tells compiler to look in those two directories for files. But your includes read
#include <mongocxx/instance.hpp>
etc. So to find those paths it needs (presumably) to look down from/usr/local/include
to find/usr/local/include/mongocxx/instance.hpp
(assuming that is correct). In which case, if compiler does not already look automatically in/usr/local/include
(I don't know if it does) you would need-I/usr/local/include
? -
Hi,
Thanks for the response
But that does not fix it :(
.pro:INCLUDEPATH += \ -I/usr/local/include/ LIBS += \ -L/usr/local/lib \ -lmongocxx \ -lbsoncxx
Thanks
-
Where are the files you include located on your hard drive exactly ?
-
Hi,
/usr/local/include/mongocxx/v_noabi/ contains folder mongocxx and /usr/local/include/bsoncxx/v_noabi/ contains folder bsoncxx.
Thanks -
I see your issue now. Go back to the original paths you were using but remove the -I before the path, they are unneeded with the INCLUDEPATH variable.
-
Hi,
Thanks it worked, I was able to import it, but another issue poped up:error: 'bsoncxx::v_noabi::builder::stream' has not been declared 20 | using bsoncxx::builder::stream::close_array; | ^~~~~~
But I can see folder stream inside builder inside bsoncxx.
In the error I see that it want's to import bsoncxx::v_noabi::builder::stream but I want it to use bsoncxx::v_noabi::bsoncxx::builder::stream
Thanks -
That I do not know.
Can you provide a minimal example that triggers this error ?
-
Sorry for the late response,
I solved the issue by reinstalling the packages
Thanks for the help.