[confluence] MongoDB > C++ Driver Compiling and Linking

9 views
Skip to first unread message

nor...@mongodb.onconfluence.com

unread,
Jan 28, 2013, 4:19:00 PM1/28/13
to mongodb...@googlegroups.com

C++ Driver Compiling and Linking

Page edited by Eric Milkie


Changes (1)

{toc}
The C+\+ driver is included in the MongoDB server source repository, and can also be downloaded as a separate, "standalone" tarball (see [C\+\+ [DOCS:C++ Driver Download]).   To compile the "standalone" C+\+ driver, run the scons command in the top-level directory of the driver sources, e.g.:

{code}cd mongo-cxx-driver-nightly/
...

Full Content

The C++ driver is included in the MongoDB server source repository, and can also be downloaded as a separate, "standalone" tarball (see C++ Driver Download).   To compile the "standalone" C++ driver, run the scons command in the top-level directory of the driver sources, e.g.:

cd mongo-cxx-driver-nightly/
scons

You may wish to compile and link client/simple_client_demo.cpp to verify that everything compiles and links fine.

Linux

Using the prebuilt library

$ cd mongo/client
$ g++ simple_client_demo.cpp -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options

Using mongo_client_lib.cpp instead of a library

If you have a compatibility problem with the library, include mongo_client_lib.cpp in your project instead. For example:

g++ -I .. simple_client_demo.cpp mongo_client_lib.cpp -lboost_thread-mt -lboost_filesystem

Windows

Note: we tend to test MongoDB with Windows using Visual Studio 2010. 2008 works, although you may have to tweak settings in some cases.

Include mongoclient.lib in your application.

To build mongoclient.lib:

scons mongoclient

Alternatively, include client/mongo_client_lib.cpp in your project.

For Windows, see also:

Other notes for Windows:

  • Compile with /MT
  • You may wish to define _CRT_SECURE_NO_WARNINGS to avoid warnings on use of strncpy and such by the MongoDB client code.
  • Include the WinSock library in your application : Linker.Input.Additional Dependencies - add ws2_32.lib.

Windows Troubleshooting

  • error LNK2005: ___ already defined in msvcprt.lib(MSVCP100.dll) libboost_thread-vc100-mt-1_42.lib(thread.obj)
    • The boost library being linked against is expecting a /MT build. If this is a release build, try using /MT instead of /MD for compilation (under Properties.C++.Code Generation).

nor...@mongodb.onconfluence.com

unread,
Jan 28, 2013, 4:19:00 PM1/28/13
to mongodb...@googlegroups.com

C++ Driver Compiling and Linking

Page edited by Eric Milkie


Changes (1)

{toc}
The C+\+ driver is included in the MongoDB server source repository, and can also be downloaded as a separate, "standalone" tarball (see [Docs:downloads]). [C\+\+ Driver Download]).   To compile the "standalone" C+\+ driver, run the scons command in the top-level directory of the driver sources, e.g.:

{code}cd mongo-cxx-driver-nightly/
...

Full Content

The C++ driver is included in the MongoDB server source repository, and can also be downloaded as a separate, "standalone" tarball (see [C\+\+ Driver Download]).   To compile the "standalone" C++ driver, run the scons command in the top-level directory of the driver sources, e.g.:

Reply all
Reply to author
Forward
0 new messages