Under Step 4, Configure the driver, I ran into the issues.
So far, any attempt of calling cmake resulted in this:
<<
CMake Error at src/bsoncxx/CMakeLists.txt:81 (find_package):
By not providing “Findlibbson-1.0.cmake” in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
“libbson-1.0”, but CMake did not find one.
Could not find a package configuration file provided by “libbson-1.0”
(requested version 1.13.0) with any of the following names:
libbson-1.0Config.cmake
libbson-1.0-config.cmake
Add the installation prefix of “libbson-1.0” to CMAKE_PREFIX_PATH or set
“libbson-1.0_DIR” to a directory containing one of the above files. If
“libbson-1.0” provides a separate development package or SDK, be sure it
has been installed.
Those files do not exist. I have libbson-1.0, but not any libbson cmake file.
So far, I found the similar questions
but those did not really help me. I feel that if I blindly start to edit some CMakeFile, this will do me no good.
If it is relevant, my last attempt at configuration used the command
cmake …
-DCMAKE_BUILD_TYPE=Release
-DBSONCXX_POLY_USE_MNMLSTC=1
-DCMAKE_INSTALL_PREFIX=/usr/local
I tried out several variants and also to execute it under sudo, same outcome.
I also tried to set CMAKE_PREFIX_PATH to something that contains the libbson library files, but as it specifically asks for a libbson cmake file, I didn’t expect it to work to begin with.
@Robert_Sanchez
You were correct, the C driver wasn’t properly built, and it works now.
Thanks, I would never have guessed that a dependency was missing from the error message.
@Ksortakh_Kraxthar That’s excellent news. Feel free to let us know if you encounter any other issues. Incidentally, depending on what version of Ubuntu you are using, you may find that a recent C driver is available directly via apt.
I’m experiencing the same problem, but installing the C driver didn’t seem to resolve it:
$ sudo apt-get install libmongoc-1.0-0
$ cmake ...
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_PREFIX_PATH=/opt/mongo-c-driver
-DCMAKE_INSTALL_PREFIX=/opt/mongo-cxx-driver
bsoncxx version: 3.5.0
CMake Error at src/bsoncxx/CMakeLists.txt:98 (find_package):
By not providing "Findlibbson-1.0.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"libbson-1.0", but CMake did not find one.
Could not find a package configuration file provided by "libbson-1.0"
(requested version 1.13.0) with any of the following names:
libbson-1.0Config.cmake
libbson-1.0-config.cmake
@Willow_Willis it is not clear what you are trying to do. The command sudo apt-get install libmongoc-1.0-0 installs the runtime library, not the development library and headers. You probably need sudo apt-get install libmongoc-dev instead.
Additionally, the packages will install everything under /usr, so passing -DCMAKE_PREFIX_PATH=/opt/mongo-c-driver is probably not what you want. If you already have a C Driver built and installed there, it is possible that it will be used instead of the C Driver from distro packages.
@Willow_Willis Not sure if it helps, but the full set of commands I used was:
sudo apt-get install libmongoc-1.0-0
sudo apt-get install libbson-1.0
sudo apt-get install cmake libssl-dev libsasl2-dev
wget https://github.com/mongodb/mongo-c-driver/releases/download/1.16.2/mongo-c-driver-1.16.2.tar.gz
tar xzf mongo-c-driver-1.16.2.tar.gz
cd mongo-c-driver-1.16.2
mkdir cmake-build
cd cmake-build
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
sudo make install
git clone https://github.com/mongodb/mongo-cxx-driver.git \
--branch releases/stable --depth 1
cd mongo-cxx-driver/build
sudo cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DBSONCXX_POLY_USE_MNMLSTC=1 \
-DCMAKE_INSTALL_PREFIX=/usr/local
sudo make EP_mnmlstc_core
sudo make
sudo make install
Especially note the second block, which I originally left out until @Robert_Sanchez pointed me at the C driver.
Might be that some parts are redundant, but worked for me.
If you are building the C driver from source, it is better to not have libmongoc-1.0-0 and libbson-1.0 installed via apt. If your distro has a new enough C Driver package, then a simple sudo apt-get install libmongoc-dev is all you need to have the C Driver available to you.
I removed the runtime library and headers, then tried installing the development library from apt. Looks like my distro doesn’t have a new enough C Driver:
$ sudo apt-get install libmongoc-dev
$ sudo cmake ..
-DCMAKE_BUILD_TYPE=Release
-DBSONCXX_POLY_USE_MNMLSTC=1
-DCMAKE_INSTALL_PREFIX=/usr/local
bsoncxx version: 3.5.0
CMake Error at src/bsoncxx/CMakeLists.txt:98 (find_package):
Could not find a configuration file for package "libbson-1.0" that is
compatible with requested version "1.13.0".
The following configuration files were considered but not accepted:
/usr/lib/x86_64-linux-gnu/cmake/libbson-1.0/libbson-1.0-config.cmake, version: 1.9.2
So I removed the development library and followed @Ksortakh_Kraxthar’s instructions for installing the mongo-c-driver from source (without installing the client libraries again). I did need to install zlib ( sudo apt-get install zlib1g-dev ) before it would make install, however.
@Willow_Willis then I suspect you are running Debian stretch, or Ubuntu Bionic. Both of those would have rather old C driver versions, which would not be sufficient for building the latest C++ driver. I’m glad you were able to sort it out. If you are interested in building packages that you can install with apt, then this post may interest you: C and C++ Driver for Debian & Ubuntu users - #2