[DOCS-8026] C++ Driver Quickstart Page missing information for beginners Created: 04/Jun/16  Updated: 11/Jan/17  Resolved: 30/Jun/16

Status: Closed
Project: Documentation
Component/s: drivers
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Task Priority: Minor - P4
Reporter: Roy Rim Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates DOCS-8158 C++ Driver Playbook Closed
Participants:
Days since reply: 7 years, 36 weeks, 4 days ago

 Description   

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


Generated at Thu Feb 08 07:55:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.