c++mongodbc++11cmakemongodb-c

Using the mongodb cxx driver in a cmake c++ project


I am new to cmake and I want to connect to a mongodb using c++ and the latest mongodb cxx driver. I managed to compile and install the driver but now I stuck with using it in my cmake project.

I installed the mongodb driver with the default settings, so it's located under /usr/local/lib/include/mongocxx/v_noabi/mongocxx.

In my cmake file i manged to get the includes resolved with:

include_directories(/usr/local/lib/include/mongocxx/v_noabi /usr/local/lib/include/bsoncxx/v_noabi)

but I don't know how to actually link the driver libs to my executable. Could any one please help me?


Solution

  • You shouldn't need to do it that way. You can and should find the C++11 driver via either CMake's find_package or via pkg_check_modules subsystems. The C++11 driver supports both.