2

I am trying to follow this guide, and I am currently at step 3.

So after running,

curl -OL https://github.com/mongodb/mongo-cxx-driver/archive/r3.0.1.tar.gz
tar -xzf r3.0.1.tar.gz
cd mongo-cxx-driver-r3.0.1/

I try to do similar commands as in the Windows guide for mongoc:

If I do just

cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=C:/mongo-cxx-driver"

I get an error

CMake Error at cmake/FindLibBSON.cmake:37 (message):
  Don't know how to find libbson; please set LIBBSON_DIR to the prefix
  directory with which libbson was configured.
Call Stack (most recent call first):
  src/bsoncxx/CMakeLists.txt:67 (find_package)

So here I have tried different things, like adding the paths to the libsson directory:

cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=C:/mongo-cxx-driver" "-DLIBBSON_DIR=C:/mongo-c-driver/lib/pkgconfig/" "-DLIBMONGOC_DIR=C:/mongo-c-driver/lib/pkgconfig/" "-DBOOST_ROOT=C:/local/boost_1_62_0/"

This actually works, but then when I try to build with

msbuild.exe ALL_BUILD.vcxproj

I get an error:

C:\Users\Erik\Documents\mongo-cxx-driver-r3.0.1\src\bsoncxx\array\view.cpp(21): fatal error C1083: Cannot open include
 file: 'bson.h': No such file or directory [C:\Users\Erik\Documents\mongocxx-driver-r3.0.1\src\bsoncxx\bsoncxx_static.v
cxproj]

This file, "bson.h" seems to reside in the direcroty

C:\mongo-c-driver\include\libbson-1.0

but I am not sure why it does not find the file or how I could make it do so.

Greatly appreciate any input on this.

Community
  • 1
  • 1
Slug Pue
  • 256
  • 1
  • 2
  • 15
  • Thanks for the detailed writeup - it made it much easier to spot the error. I have an answer below that I think will unblock you. – acm Oct 02 '16 at 23:33

2 Answers2

4

You are not setting LIBBSON_DIR and LIBMONGOC_DIR correctly. They should, in your case, be both set to C:\mongo-c-driver. The build system will automatically add include and lib to that base path as needed. You might find reading the appveyor script informative:

acm
  • 12,183
  • 5
  • 39
  • 68
0

October, 18 2016

This issue happens to Mac OS X as well, and maybe to other Un*xes.

  1. Use version 3.0.2 (at least). (The official guide mentions 3.0.1, but there is a bug fixed in 3.0.2).
curl -OL https://github.com/mongodb/mongo-cxx-driver/archive/r3.0.2.tar.gz
  1. I didn't change to build directory, but to the root:
cd mongo-cxx-driver-r3.0.2 
  1. 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
  1. Make and Install
make

make install 
  1. The command to compile the test from the official guide (change /opt/mongodbDriverCpp to 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
  1. Run (start the mongodb server first)
export LD_LIBRARY_PATH=/opt/mongodbDriverCpp/lib

./run.test
cibercitizen1
  • 20,944
  • 16
  • 72
  • 95