Preparation before installation:
1/ Install the boost library
2/ Install the scons program
Method 1:
$ git clone git://github.com/mongodb/mongo.git
$ cd mongo
$ cat docs/building.md
$ scons .
After a period of compilation, the server and client of mongodb, as well as the c++ client library can be generated.
Method 2: Use scons to compile (the scons program must be installed first)
Download the mongo source code from the official website (http://www.mongodb.org/downloads), the version I downloaded is
mongodb-src-r2.0.7.tar.gz
After decompression, generate mongodb-src-r2.0.7 directory, cd to this directory
Then execute the command:
scons –prefix=/urs/local/mongo
At that time, three directories bin, include, lib will be generated in /urs/local/mongo
in:
The bin contains the server and client of mongo, and some other tools
include is the header file of mongo
lib is the client library, the cpp client library generated here
Finish!
In the source code directory, there are some simple test samples under client/example, which can be compiled:
cd to client/example
compile first.cpp
g++ first.cpp -o first
-I/usr/local/mongo/include/mongo -L/usr/local/mongo/lib
-llibmongoclient.a -lboost_thread -lboost_filesystem
-lboost_program_options -lboost_system
Compile clientTest.cpp
g++ clientTest.cpp -o clientTest
-I/usr/local/mongo/include/mongo -L/usr/local/mongo/lib
-llibmongoclient.a -lboost_thread -lboost_filesystem
-lboost_program_options -lboost_system
Note:
Be careful about the linking order of the libraries in the compilation command, it will affect whether the compilation is successful! ! !