Mongo-cxx-driver: Windows platform compilation record, mongocxxdriver

Source: Internet
Author: User

Mongo-cxx-driver: Windows platform compilation record, mongocxxdriver
Mongo-cxx-driver for Windows

The official code source is here: Release.
Tools used:
1. Visual Studio. I use VS2013.
2. Boost library. The version I used is 1.55.Note that by default, only the static library is compiled during compilation. You need to manually compile the dynamic library and add the bjam command line to link = shared. This step is very important. Otherwise, you may be prompted that the Boost library file cannot be found during subsequent links.I have been stuck here for a long time.
3. Python. 2.7 is the best. Version 3 or later is not supported.
4. Scons. This is a tool similar to CMake and cannot compile this library without it. However, this is not easy to use, and it is not easy to use with CMake.

Start Compilation

During compilation of this library, every database in the ABI format needs to be re-compiled. Nima, isn't one compilation all done?
First, MDd dynamically links to the debugging static library of the Runtime Library:

scons --32 --prefix=path_to_install --cpppath=path_to_boost_include --libpath=path_to_boost_lib --dynamic-windows --dbg=on install 

Second, MD dynamically links to the static library of the Runtime Library:

scons --32 --prefix=path_to_install --cpppath=path_to_boost_include --libpath=path_to_boost_lib --dynamic-windows install 

The difference is-dbg = on here. -Dynamic-windows indicates that the Runtime Library is dynamically linked. This is the most useful. If you want to statically link to the Runtime Library (rarely used, at least for me), just remove this option.
If you want to compile the database into a dynamic library, you only need to add the-sharedclient option, which specifies to compile the database into a dynamic library.

Compile all the libraries in the ABI format, which must be compiled four times in total. Anti-humanity, Nima !!! Compilation speed is not flattering, It is very slow.

Test procedure

If you are a static library linked to mongo-cxx-driver, remember to add the pre-processor static_lib1_client. Otherwise, the ABI may not be matched. If it is not added, it is linked to the dynamic library.
Another problem with the link to the static library of libbench client is that the Boost library has been defined. In this case, you need to add the library to ignore the specified default library, otherwise, the link will fail. This is another trap, alas...
Test code:

# Include <iostream> # include <WinSock2.h> # include <mongo/client/dbclient. h> void run () {mongo: DBClientConnection c; c. connect ("localhost");} int main (int argc, char ** argv) {mongo: client: initialize (); try {run (); std :: cout <"connection successful" <std: endl;} catch (const mongo: DBException & e) {std: cout <"error:" <e. what () <std: endl;} getchar (); return 0 ;}

Winsock2.h must be included before dbclient. h. This is required by this library. If it works with MFC, it is estimated that there are various compilation errors. Fortunately, I have no longer used MFC.

So much. To sum up, the use of CMake in this library may be better. There are many compilation errors and various pitfalls that need to be paid attention to during Windows compilation. Linux does not have these problems.

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.