CMake error installing mongo-c-driver

Hello everybody,
I am new to MongoDB and I’m trying to install the mongo-c-driver and the connector.
But I always get the following CMake error:


Does anybody have a idea how to fix it?

Hi @Simon_Reitbauer,

The installation instructions have the last argument to the cmake command as the path to the directory containing CMakeLists.txt. Try adding .. to the end of your cmake command.

Thank you, now it’s working. Totally forgot that.

Well, now I am trying to install the mongocxx driver with this command:

cmake -G “Visual Studio 16 2019” \ -DBOOST_ROOT=D:\boost_1_72_0 \ -DCMAKE_PREFIX_PATH=C:\mongo-c-driver \ -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \ …
found on http://mongocxx.org/mongocxx-v3/installation/, but I get the following error:

Please excuse my questions, but I have never installed anything like this.

Hi Simon,

It appears you’re building the C driver with MinGW’s build tools, and the C++ driver with Visual Studio. I actually did not realize this until I tried it, but those need to be consistent. Either build both with MinGW or both with Visual Studio. In your case, since you have the Visual Studio compiler available, try building and installing the C driver with Visual Studio instead of MinGW. Then I think configuring the C++ driver should work.

Best,
Kevin

1 Like

So, I tried this version now, but it won’t work. Here is the error:

Apologies for all of these build frustrations. That is because the C driver is trying to determine the current version from the git history, but is unable to execute git. You can either install git, or more simply specify the version manually by adding -DBUILD_VERSION="1.16.2" to the cmake arguments, i.e.

cmake -G "Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver -DCMAKE_PREFIX_PATH=C:\mongo-c-driver -DBUILD_VERSION="1.16.2" ..
1 Like

So, now I get another error, when I try to execute “msbuild.exe /p:Configuration=RelWithDebInfo ALL_BUILD.vcxproj” or “msbuild.exe INSTALL.vcxproj”:


I’ve checked the web but found nothing useful for that. Looks like a Windows error to me.

That may be due to artifacts of the previous build interfering. If you haven’t already, try deleting the cmake-build directory and rebuilding.

Not, thats not working. I try to contact the Microsoft support.

So, the c-driver is installed correctly now, building the cxx-driver also works fine. But when I try to install it, I get an error.

Command: cmake -G “Visual Studio 16 2019” \ -DBOOST_ROOT=D:\boost_1_72_0 \ -DCMAKE_PREFIX_PATH=C:\mongo-c-driver \ -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \ …

Error:

Hi Simon,

Ah, I believe this is an error on newer Visual Studio compilers (see https://jira.mongodb.org/browse/CXX-1678, which is fixed on master but not yet released). This is related to extra alignment specifiers in the C driver, which can be disabled with -DENABLE_EXTRA_ALIGNMENT=OFF to work around this issue (it is recommended to disable the extra alignment anyway, and would be the default if it was not an ABI breaking change).

I tested on a Windows machine with VS 2019 to ensure I wasn’t missing anything, and was able to build both with the following:

# Building C driver
cmake -G "Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX="C:\mongo-c-driver-1.16.2" -DENABLE_EXTRA_ALIGNMENT=OFF ..
cmake --build . --target INSTALL --config Debug
# Building C++ driver
cmake -G "Visual Studio 16 2019" -DCMAKE_PREFIX_PATH="C:\mongo-c-driver-1.16.2" -DBOOST_ROOT="C:\boost_1_72_0\boost_1_72_0" -DCMAKE_INSTALL_PREFIX="C:\mongo-cxx-driver-3.4.1" ..
cmake --build . --target INSTALL --config Debug

Apologies again for all of the frustrations. The C++ driver is actively tested against Visual Studio 2017, but not yet VS 2019 compilation, but hopefully should be soon.

2 Likes

Thank you, now everything works fine!

One last thing: I’ve included everything needed now, but I get an linking error related to mongocxx.lib.

Problem has been solved, thank you for the good support!

Fantastic, glad to hear!

1 Like