Creating a MongoDB C driver on Windows

What have i done so far

I read the installation guide .

OpenSSL library for Windows is installed after downloading the installation file .

Download and extract the Mongo C Driver directory from GitHub .

Installed CMake for Windows after downloading from the CMake website .

I went to mongo-c-driver/src/libbson and ran cmake -G "Visual Studio 14 2015 Win64" and it prints (possibly) success.

D:\works\test\mongo-c-driver\src\libbson>cmake -G "Visual Studio 14 2015 Win64" Current version (from VERSION_CURRENT file): 1.4.0-dev Previous release (from VERSION_RELEASED file): 1.3.5 -- Check if the system is big endian -- Searching 16 bit integer -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of unsigned short -- Check size of unsigned short - done -- Using unsigned short -- Check if the system is big endian - little endian -- Looking for snprintf -- Looking for snprintf - found -- Looking for _set_output_format -- Looking for _set_output_format - not found -- Performing Test BSON_HAVE_TIMESPEC -- Performing Test BSON_HAVE_TIMESPEC - Success -- struct timespec found -- Configuring done -- Generating done -- Build files have been written to: D:/works/test/mongo-c-driver/src/libbson

msbuild ALL_BUILD.vcxproj and prints success.

Problem

He mongo-c-driver to mongo-c-driver and ran `cmake -G" Visual Studio 14 2015 Win64 "and prints such errors.

-- Found BSON: BSON-NOTFOUND;ws2_32
-- Found OpenSSL: optimized;D:/apps/OpenSSL-Win64/lib/VC/ssleay32MD.lib;debug;D:/apps/OpenSSL-Win64/lib/VC/ssleay32MDd.lib;optimized;D:/apps/OpenSSL-Win64/lib/VC/libeay32MD.lib;debug;D:/apps/OpenSSL-Win64/lib/VC/libeay32MDd.lib (found version "1.0.2h") -- Searching for sasl/sasl.h -- Not found (specify -DCMAKE_INCLUDE_PATH=C:/path/to/sasl/include for SASL support) -- Searching for libsasl2 -- Not found (specify -DCMAKE_LIBRARY_PATH=C:/path/to/sasl/lib for SASL support) -- Configuring incomplete, errors occurred! See also "D:/works/test/mongo-c-driver/CMakeFiles/CMakeOutput.log".

I searched sasl.h from my drives, but they are not. I also searched for it from OpenSSL GitHub , but it does not have sasl.h

I downloaded and opened cyrus-sasl from here , but I was stuck with it. I don’t know what to do with it.

How can I make a successful build of the MongoDB C driver?

+5
source share
2 answers

It looks like the libsasl2 port for Windows is not complete. Although I eventually got libsasl to compile, libsasl2 was not created. It looks like SASL is used by MongoDB C Driver for Kerberos. I do not know if they tried to get Kerberos to work with the C-driver on Windows without the libsasl2 library port.

However, I was able to eventually compile the MongoDB C driver. At first I tried to compile using the C: \ subdirectories, unlike C: \ mongo-c-driver, etc., but this did not work, but when I compiled Using the directory structure in the documentation, compilation was successful.

To compile it, I disabled the SASL library in compilation. I do not think this will be necessary if you do not need to use Kerberos. At first I had to explicitly disable SASL (perhaps due to the use of 64-bit) - this can be done using -DENABLE_SASL=no when compiling the mongo-c driver.

Here are the steps:

Using this page you can find the source of the drivers: https://github.com/mongodb/mongo-c-driver/releases (1.3.5)

Got cmake from https://cmake.org/download/

Installed cmake using the Windows installer, adding cmake to the path for all users. I had to log out and log in to get the upgrade path.

Then I copied the source mongo-c-driver-1.3.5 to c: \ mongo-c-driver-1.3.5

Then

I used the Visual Studio MSBuild command line starting with Run As Administrator

 C:\mongo-c-driver-1.3.5\src\libbson>cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -G "Visual Studio 14" -- The C compiler identification is unknown -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:3 (project): No CMAKE_C_COMPILER could be found. CMake Error at CMakeLists.txt:3 (project): No CMAKE_CXX_COMPILER could be found. -- Configuring incomplete, errors occurred! See also "C:/mongo-c-driver-1.3.5/src/libbson/CMakeFiles/CMakeOutput.log". See also "C:/mongo-c-driver-1.3.5/src/libbson/CMakeFiles/CMakeError.log". 

It turns out that C compilers are not installed with a standard Visual Studio installation, so I had to install the C ++ Visual Studio component. I installed C ++ Common Tools, but not MFC for C ++ and XP. However, it will use 3 GB of disk space (started at 39.5, ended at 37.0, so 2.5 GB was used).

Once it has been installed:

 cd \mongo-c-driver-1.3.5\src\libbson cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -G "Visual Studio 14" . msbuild.exe ALL_BUILD.vcxproj msbuild.exe INSTALL.vcxproj cd ..\.. C:\mongo-c-driver-1.3.5>cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -DENABLE_SSL=WINDOWS -DBSON_ROOT_DIR=C:\libmongoc -G "Visual Studio 14" . -- The C compiler identification is MSVC 19.0.23026.0 -- The CXX compiler identification is MSVC 19.0.23026.0 -- Check for working C compiler using: Visual Studio 14 2015 -- Check for working C compiler using: Visual Studio 14 2015 -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler using: Visual Studio 14 2015 -- Check for working CXX compiler using: Visual Studio 14 2015 -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found BSON: C:/libmongoc/lib/bson-1.0.lib;ws2_32 -- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR) -- Searching for sasl/sasl.h -- Not found (specify -DCMAKE_INCLUDE_PATH=C:/path/to/sasl/include for SASL support) -- Searching for libsasl2 -- Not found (specify -DCMAKE_LIBRARY_PATH=C:/path/to/sasl/lib for SASL support) Current version (from VERSION_CURRENT file): 1.3.5 -- Configuring done -- Generating done -- Build files have been written to: C:/mongo-c-driver-1.3.5 

OpenSSL was not present, so I got the 32-bit Win32 OpenSSL v1.0.2h from http://slproweb.com/products/Win32OpenSSL.html

Then I installed OpenSSL. Changed the installation directory to C: \ work \ OpenSSL-Win32, and I allowed the OpenSSL installer to install the binaries in the Windows system directory

Now,

 C:\mongo-c-driver-1.3.5>cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -DENABLE_SSL=WINDOWS -DBSON_ROOT_DIR=C:\libmongoc -G "Visual Studio 14" . -- Found OpenSSL: optimized;C:/work/OpenSSL-Win32/lib/VC/ssleay32MD.lib;debug;C:/work/OpenSSL-Win32/lib/VC/ssleay32MDd.lib;optimized;C:/work/OpenSSL-Win32/lib/VC/libeay32MD.lib;debug;C:/work/OpenSSL-Win32/lib/VC/libeay32MDd.lib (found version "1.0.2h") -- Searching for sasl/sasl.h -- Not found (specify -DCMAKE_INCLUDE_PATH=C:/path/to/sasl/include for SASL support) -- Searching for libsasl2 -- Not found (specify -DCMAKE_LIBRARY_PATH=C:/path/to/sasl/lib for SASL support) Current version (from VERSION_CURRENT file): 1.3.5 -- Configuring done -- Generating done -- Build files have been written to: C:/mongo-c-driver-1.3.5 C:\mongo-c-driver-1.3.5> msbuild.exe ALL_BUILD.vcxproj (lots of output, with some yellow warnings, but no red errors) msbuild.exe INSTALL.vcxproj 

And now the mongo-c-driver is built. I can use it with Visual C ++ to connect to my MongoDB server using ssl.

Now I'm trying to figure out how to get Embarcadero RADStudio C ++ Builder to use the new mongo-c driver. Just copying the .dll to the application folder leads to an interruption in the bson dll. The stack trace looks like this:

Stack Trace Screenshot

+3
source

There are two errors in this release. - libbson must be installed and accessible - mongoc is configured for cyrus sasl, in which case it must be installed and accessible

Both can easily be fixed, and later versions of mongoc will no longer be erroneous if cyrus sasl or openssl is not available, but will instead use native Windows implementations. The driver can also be configured without them. Available options and configuration values:

 -DENABLE_SASL=[CYRUS|SSPI|AUTO|OFF] -DENABLE_SSL=[OPENSSL|WINDOWS|DARWIN|AUTO|OFF] 

Unfortunately, installing mongoc cmake will not automatically install batch libbson for you, this may be fixed in the future, but now you need to install it separately.

In short, to install the mongoc driver on Windows:

Download and extract mongoc ( https://github.com/mongodb/mongo-c-driver/releases ). mongoc releases come with libbson sources, so there is no need to download them separately. Enter the libbson directory, "src / libbson", and then:

 cd c:/path/to/mongoc/ cd src/libbson # Configure and install libbson cmake.exe -G "Visual Studio 14 2015 Win64" \ -DCMAKE_INSTALL_PREFIX=c:/mongoc msbuild.exe ALL_BUILD.vcxproj msbuild.exe INSTALL.vcxproj # Installs libbson cd ../.. # Go back to the root folder of the release sources # Configure and install mongoc cmake.exe -G "Visual Studio 14 2015 Win64" \ -DCMAKE_INSTALL_PREFIX=c:/mongoc \ -DCMAKE_PREFIX_PATH=c:/mongoc/lib/cmake \ -DENABLE_AUTOMATIC_INIT_AND_CLEANUP:BOOL=OFF \ -DENABLE_SSL=WINDOWS \ # Use Windows Native TLS, rather then OpenSSL -DENABLE_SASL=SSPI # Use Windows Native SSPI, rather then Cyrus SASL msbuild.exe ALL_BUILD.vcxproj msbuild.exe INSTALL.vcxproj 
+2
source

All Articles