简体   繁体   中英

how to install mongodb drivers for c++ in ubuntu?

I want to develop a fairly simple application using c++ for mongoDB and I follow their tutorials : http://www.mongodb.org/pages/viewpage.action?pageId=133415

and for installing driver I followed this one : https://groups.google.com/forum/?fromgroups=#!msg/mongodb-user/-mPG7MDJgm8/nZSiN42DJWIJ (Waitman Gobble/5 jun answer)

but yet when I try to compile a simple application I will get following error :

fatal error: client/dbclient.h: No such file or directory

I'm pretty sure the problem is MongoDB c++ driver hasn't installed yet.

How can I install it properly?

In Ubuntu packages for development are separate from packages for general use.

In order to make use of the mongodb header files and clientlibraries, you need to sudo apt-get install mongodb-dev libmongo-client-dev - this adds the headers that will allow you to #include the relevant header files.

This assumes that you've already installed the libmongo-client and mongodb packages, which contains the client library, although they should be installed when you install the -dev packages.

If you download the driver source code from here ,

Unpack and unzip

tar xzf mongodb-linux-x86_64-v2.0-latest.tgz 

Then cd into the directory.

cd mongo-cxx-driver-v2.0/

Then use scons to build

scons

and install

sudo scons install

Then to compile code shown in the tutorial you need to also specify the /usr/local/include/mongo directory as a include file search path.

sudo  g++ tutorial.cpp -I/usr/local/include/mongo -lmongoclient 
-lboost_thread -lboost_filesystem -lboost_program_options -o tutorial

Then to run it you will need to edit the /etc/ld.so.conf file

sudo vi /etc/ld.so.conf 

and add

/usr/local/lib

Then run

sudo ldconfig

and run the tutorial

$ ./tutorial 
connected ok

As an alternative to editing the ld.so.config file you can use the LD_LIBRARY_PATH environment variable. So you would do

export LD_LIBRARY_PATH=/usr/local/lib
$ ./tutorial 
connected ok

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM