Problems trying to compile MongoCxx on Windows

Hi, i’m currently trying to compile mongocxx- driver on Window 10 but I’m having trouble understanding how to resolve some errors. I search in all directory but i don’t found this libbson-1.0. I followed the instruction on this page “Windows” and the c-driver have been successfully installed. Below, I’ve reported the error that is being generated. I’ve seen a topic where a similar issue was discussed, but it was resolved in a Linux environment, I apologize in advance if I have opened another similar topic.

‘’’
– Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
– No build type selected, default is Release
– Auto-configuring bsoncxx to use boost std library polyfills since C++17 is inactive and compiler is MSVC
bsoncxx version: 3.8.0
CMake Error at src/bsoncxx/CMakeLists.txt:114 (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.24.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.

– Configuring incomplete, errors occurred!
‘’’

Hi @walter_trupia, could you please try this step by step guide to build and install C/C++ driver on windows - Getting Started with MongoDB and C++ | MongoDB ?

I tried this guide earlier this afternoon, but unfortunately, it didn’t work either. I used the specified versions of each software, but it still generated several errors as soon as I ran this command: “cmake … -G “Visual Studio 17 2022” -A x64 -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS=”/Zc:__cplusplus /EHsc" -DCMAKE_PREFIX_PATH=C:\mongo-c-driver -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver." I will try again this afternoon

I have tried the guide again, following each step carefully. I used the versions of the software specified in the guide, and the only difference is that I am using Windows 10 instead of Windows 11.

– Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
– No build type selected, default is Release
– Auto-configuring bsoncxx to use C++17 std library polyfills since C++17 is active and user didn’t specify otherwise
bsoncxx version: 3.7.0
CMake Error at src/bsoncxx/CMakeLists.txt:113 (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.

– Configuring incomplete, errors occurred!

This is the output of this script: cmake … -G “Visual Studio 17 2022” -A x64 -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS=“/Zc:__cplusplus /EHsc” -DCMAKE_PREFIX_PATH=C:\mongo-c-driver -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver

How is the C driver installed? Are you using the same tutorial to build and install C driver as well?

Yes, I followed the same tutorial for the C drivers as well.

Can you check whether C driver is installed at C:\mongo-c-driver? This is the path we are providing to CMAKE_PREFIX_PATH variable and should contain the libbson-1.0Config.cmake

You also try encapsulating the prefix and install path in quotes, ie.

cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS="/Zc:__cplusplus /EHsc" -DCMAKE_PREFIX_PATH="C:\mongo-c-driver" -DCMAKE_INSTALL_PREFIX="C:\mongo-cxx-driver"

libbson image mongo-c-driver

In the path C:\mongo-c-driver-1.23.0\src\libbson or \libmongoc, you can find the files that I listed.

I tried running it like this:

cmake … -G “Visual Studio 17 2022” -A x64 -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS=“/Zc:__cplusplus /EHsc” -DCMAKE_PREFIX_PATH=“C:\mongo-c-driver-1.23.0” -DCMAKE_INSTALL_PREFIX=“C:\Repos\mongo-cxx-driver-r3.7.0”

And like this:

cmake … -G “Visual Studio 17 2022” -A x64 -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS=“/Zc:__cplusplus /EHsc” -DCMAKE_PREFIX_PATH=“C:\mongo-c-driver” -DCMAKE_INSTALL_PREFIX=“C:\Repos\mongo-cxx-driver”

Because the folder containing the C drivers is “mongo-c-driver-1.23.0,” while the folder for the C++ drivers is “C/Repos/mongo-cxx-driver-r3.7.0.”

The CMAKE_PREFIX_PATH should point to the directory where C driver is installed. The directory should look something like below, with include, bin, lib and share folder. The needed cmake file is present inside the lib folder:

It seems like you are currently pointing the CMAKE_PREFIX_PATH to the directory where the C driver source code is present, which doesn’t seem right. Please figure out the location where the C driver was installed. Ideally it should be C:\mongo-c-driver if one followed the steps in the tutorial.

Yes, you were right; I managed to solve it by specifying the path where I had installed the mongo-c-driver. Thank you for the support.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.