发布于 2015-09-14 15:08:27 | 288 次阅读 | 评论: 0 | 来源: 网络整理
The C++ client library can be found at http://dl.mongodb.org/dl/cxx-driver .
注解
Despite the word ‘linux’ in the filenames, these files are mostly source code and thus should be applicable to all operating systems.
If you have the full MongoDB source code, the driver code is part of it. This is available on GitHub and also on the MongoDB Downloads page.
The full server source is quite large, so the tarballs above may be easier. Also if using the full server source tree, use scons mongoclient to build just the client library.
The C++ driver is included in the MongoDB server source repository, and can also be downloaded as a separate, “standalone” tarball (See Download C++ Driver). 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.
cd mongo/client
g++ simple_client_demo.cpp -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options
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
注解
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:
- bson/bsondemo/bsondemo.vcxproj
- client/examples/simple_client_demo.vcxproj
- Prebuilt Boost Libraries
- Prebuilt Boost Libraries only necessary for versions < 2.1.1
- Boost 1.49 source is now included directly in version 2.1.1+
- /tutorial/build-mongodb-with-visual-studio-2010
Other notes for Windows:
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).