Search code examples
mongodbstatic-librariesmongo-cxx-driver

Mongocxx static driver example fails


I followed the instruction at to build static library http://mongoc.org/libmongoc/current/installing.html for MongoDB C Driver (version 1.9.2). It installed correctly and can build examples as

gcc -o hello_mongoc hello_mongoc.c $(pkg-config --libs --cflags libmongoc-static-1.0)

Next I wanted a mongcxx static library. I did these steps on Ubuntu 16.04 as specified here: https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/ after static mongo c driver installation

  1. git clone https://github.com/mongodb/mongo-cxx-driver.git \ --branch releases/stable --depth 1 cd mongo-cxx-driver/build

  2. cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..

  3. sudo make EP_mnmlstc_core

  4. make && sudo make install

Now when I try to run the sample program

    roshan@bolt:~$ c++ --std=c++11 test.cpp $(pkg-config --cflags --libs libmongocxx-static)
Package libmongocxx-static was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libmongocxx-static.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libmongocxx-static' found
    test.cpp:3:47: fatal error: bsoncxx/builder/stream/document.hpp: No such file or directory
    compilation terminated.

and

    roshan@bolt:~$ pkg-config --cflags libmongocxx-static
Package libmongocxx-static was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libmongocxx-static.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libmongocxx-static' found

Also, I noticed:

/usr/local/lib/libmongocxx.a is being create after sudo make install but not libmongocxx-static.

After all these steps:

roshan@bolt:/usr/local/lib$ ls
cmake             libbson-1.0.so.0.0.0  libmongoc-1.0.so        ocaml
libbson-1.0.a     libbsoncxx.a          libmongoc-1.0.so.0      pkgconfig
libbson-1.0.la    libbson-static-1.0.a  libmongoc-1.0.so.0.0.0  python2.7
libbson-1.0.so    libmongoc-1.0.a       libmongoc-static-1.0.a  python3.5
libbson-1.0.so.0  libmongoc-1.0.la      libmongocxx.a

Solution

  • I'm not sure why this was done, but that documentation was updated to reflect changes on master that do not yet exist on the current releases/stable branch. The work to add the -static versions of the mongocxx packages happened on the master branch after the v3.1 branch (where releases/stable currently points) was pulled.

    Can you see if the above process works for you when you check out the r3.2.0-rc1 tag? Hopefully we are releasing r3.2.0 very soon, so it would be good to confirm that it works for you.