This issue happens to Mac OS X as well, and maybe to other Un*xes.
- Use version 3.0.2 (at least). (The official guide mentions 3.0.1, but there is a bug fixed in 3.0.2).
- I didn’t change to
builddirectory, but to the root:
- If the C mongo driver (and libbson) isn’t at the default directory, tell it to the cmake command, as well as say we are featuring modern C++ (11, 14, …). In my case: C mongo driver is on /opt/mongodbDriverCpp (the same place to put on C++ mongo driver).
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/mongodbDriverCpp -DLIBBSON_DIR=/opt/mongodbDriverCpp -DLIBMONGOC_DIR=/opt/mongodbDriverCpp -DCMAKE_CXX_STANDARD=14
- Make and Install
make make install
- The command to compile the test from the official guide (change
/opt/mongodbDriverCppto your right directory):
c++ --std=c++11 test.cpp -o run.test -I/opt/mongodbDriverCpp/include/bsoncxx/v_noabi -I /opt/mongodbDriverCpp/include/mongocxx/v_noabi/ -L /opt/mongodbDriverCpp/lib -l mongocxx -l bsoncxx
- Run (start the mongodb server first)
export LD_LIBRARY_PATH=/opt/mongodbDriverCpp/lib ./run.test