-
Type: Task
-
Resolution: Duplicate
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: drivers
-
Labels:None
The github quickstart guide for the C++ driver (not legacy) is missing some details that makes compiling and running the example impossible, at least for me. Forgive me if some of this is obviously wrong as I'm not a C/C++ developer and have no familiarity with the build tools.
https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(New-Driver)
When installing the C drivers (not C++) part of the build process also installs the C drivers to a default (configurable) destination and also pushes the C driver .pk files to /usr/local/lib/pkgconfig/.
The C++ drivers, however, do not install to any destination at all. Instead the C++ drivers are built within the [driverpath]/build path and pkgconfig .pk files are generated within the [driverpath]/build/install/lib/pkgconfig path.
This means running the instructions below to compile the example will not work.
[PKG_CONFIG_PATH=CDRIVER_INSTALL_PATH/lib/pkgconfig] c++ --std=c++11 hellomongo.cpp -o hellomongo $(pkg-config --cflags --libs libmongocxx)
Instead I had to first set PKG_CONFIG_PATH to point to both /usr/local/lib/pkgconfig and [driverpath]/build/install/lib/pkgconfig
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:[driverpath]/build/install/lib/pkgconfig
Or alternatively I could copy all *.pk files from [driverpath]/build/install/lib/pkgconfig to /usr/local/lib/pkgconfig/. However ultimately having *.pk files pointing to [driverpath]/build/install/lib is probably not ideal anyway.
The instructions to compile also only reference the libmongocxx library. But the code includes headers for bson library as well. So it needs to include libbsoncxx as well.
And finally since the C++ driver libraries were not passed to the linker my executable failed to run. So for me to get this to run I had to do this:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:[driverpath]/build/install/lib/pkgconfig c++ -Wl,-rpath /home/vagrant/mongo-cxx-driver/build/install/lib/ --std=c++11 hellomongo.cpp -o hellomongo $(pkg-config --cflags --libs libmongocxx libbsoncxx)
Regards,
Roy
- duplicates
-
DOCS-8158 C++ Driver Playbook
- Closed