Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building MongoDB C Driver in Windows

Tags:

mongodb

What I did so far

I read the installation guide.

Installed OpenSSL library for Windows after downloading a setup file.

Downloaded and extracted a Mongo C Driver directory from GitHub.

Installed CMake for Windows after downloading from CMake web site.

Went to mongo-c-driver/src/libbson and run cmake -G "Visual Studio 14 2015 Win64" and it prints (maybe) 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

Executed msbuild ALL_BUILD.vcxproj and prints the success.

The problem

Went to mongo-c-driver and run `cmake -G "Visual Studio 14 2015 Win64" and prints errors like this.

-- 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 looked for sasl.h from my disks but there is none. I also looked for it from OpenSSL GitHub but it does not have sasl.h

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

How can I do the successful build of MongoDB C Driver?

like image 977
Hyunjik Bae Avatar asked May 22 '16 08:05

Hyunjik Bae


1 Answers

It appears that the libsasl2 port to Windows is not complete. Although I did ultimately get libsasl to compile, there was no libsasl2 produced. It appears that SASL is used by MongoDB C Driver for Kerberos. I don't know if they have tried to get Kerberos working with the C Driver on Windows without a port of the libsasl2 library.

I was, however, able to get the MongoDB C Driver to ultimately compile. I initially tried to compile using subdirectories of C:\, as opposed to C:\mongo-c-driver etc., but that didn't work well, but when I compiled using the directory structure in the documentation, the compile succeeded.

To get it to compile, I disabled the SASL library in the compilation. I don't think it will be needed unless you need to use Kerberos. I initially had to explicitly disable SASL (perhaps because of using 64 bit) -- that can be done with -DENABLE_SASL=no when compiling the mongo-c-driver.

Here are the steps:

Got driver source from this page: 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 back in to get the path to update.

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

Then,

I used the Visual Studio MSBuild Command Prompt, started 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".

Turns out that the C compilers are not installed with a standard installation of Visual Studio, so I had to install C++ component of Visual Studio. I installed C++ Common Tools, but not MFC for C++ nor XP Support. That said it would use 3 GB of disk space (started at 39.5, ended at 37.0, so 2.5 GB used)

Once that was 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 obtained 32 bit Win32 OpenSSL v1.0.2h from http://slproweb.com/products/Win32OpenSSL.html

Then, I installed OpenSSL. Changed installation directory to C:\work\OpenSSL-Win32, and I allowed the OpenSSL installer to install the binaries into 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 has been built. I can use it with Visual C++ to connect to my MongoDB server using ssl.

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

Screenshot showing stack trace

like image 179
nachbar Avatar answered Sep 18 '22 00:09

nachbar