Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-8026

C++ Driver Quickstart Page missing information for beginners

    • Type: Icon: Task Task
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • 01112017-cleanup
    • 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

            Assignee:
            Unassigned Unassigned
            Reporter:
            roy.rim@mongodb.com Roy Rim
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              7 years, 47 weeks, 6 days ago