Using CMake and VC 2013 to install MongoDB C driver under Windows

Source: Internet
Author: User
Tags install mongodb openssl



Windows installation of MongoDB C language Program driver must rely on cross-compiling software cmake, but the official website of the documents for some details account of very unclear, yesterday took half a day, finally successfully installed, the steps are as follows:



1. Download MongoDB to extract the Mongo-c-driver-1.1.4.zip source code to the D: root directory (this directory path can be selected as needed).


2, download Libbson Library, https://github.com/mongodb/libbson/releases/download/1.1.6/libbson-1.1.6.tar.gz, unzip it. Rename the extracted libbson-1.1.6 folder to "Libbson" and replace the D:\mongo-c-driver-1.1.4\src\libbson directory (the original directory that Mongo-c-driver comes with is an empty directory). 3, when the SSL function is required, download the appropriate version of OpenSSL under Windows (http://slproweb.com/products/Win32OpenSSL.html), such as OpenSSL 1.0.1m, installed in C \ The Openssl-win64 path. Add the environment variable "Openssl_root_dir" to the Windows system with a value of "C:\OpenSSL-Win64". 4, install CMake Software (http://www.cmake.org), install version 3.2.2. The official Website documentation recommends using visual 2010 and trying to compile with 2013. 5. Install with Windows command line, so add the path of the compiler "msbuild.exe" to the environment variable path First: "C:\Program Files (x86) \msbuild\12.0\bin". Because the installation of the Mongo-c-driver library requires the support of the Bson library, it is done by compiling the Bson library first, and then compiling the mongo-c-driver sequence. Do this in turn:
1) Enter the bson library directory, which contains the script file CMakeLists.txt for compiling libbson:
cd d: \ mongo-c-driver-1.1.4 \ src \ libbson
2) Use CMake to generate the compilation environment of Visual Studio 2013. Specify the D: \ mongo-c-driver directory as the final output installation directory of the bson library.
cmake -G "Visual Studio 12 Win64" "-DCMAKE_INSTALL_PREFIX = D: \ mongo-c-driver"
At this time, compiled files such as libbson.sln, ALL_BUILD.vcxproj, INSTALL.vcxproj, etc. will be generated in the d: \ mongo-c-driver-1.1.4 \ src \ libbson directory.
3) Note that compiling ALL_BUILD.vcxproj will cause an error, because one of the projects test-libbson.vcxproj cannot be successfully compiled due to the character set. Open libbson.sln with vs2013, delete the test-libbson project from all projects, the ALL_BUILD.vcxproj file will delete the entry accordingly, save and exit.
4) Compile the bson library:
msbuild.exe ALL_BUILD.vcxproj
5) Install the bson library:
msbuild.exe INSTALL.vcxproj
At this time, the corresponding bin, lib, and include library files of bson have been generated in the D: \ mongo-c-driver directory. The bson library compilation is complete.
6) Continue to install mongo-c-driver in the same way, and also install it under D: \ mongo-c-driver:
cd d: \ mongo-c-driver-1.1.4
cmake -G "Visual Studio 12 Win64" "-DCMAKE_INSTALL_PREFIX = d: \ mongo-c-driver" "-DBSON_ROOT_DIR = d: \ mongo-c-driver"
(The above sentence indicates that the output location of the compiled mongo-c-driver and the required environment variable "BSON_ROOT_DIR" are both "d: \ mongo-c-driver")
msbuild.exe ALL_BUILD.vcxproj
msbuild.exe INSTALL.vcxproj
7) Check the d: \ mongo-c-driver directory. The bson-1.0.lib and mongoc-1.0.lib files are included in the lib folder. The corresponding dynamic libraries are in the bin folder, and the header files are in the include folder.
The entire compilation is complete.

Using CMake and VC 2013 to install MongoDB C driver under Windows


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.