2

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?

EdChum
  • 376,765
  • 198
  • 813
  • 562
Vahid Hashemi
  • 5,182
  • 10
  • 58
  • 88

2 Answers2

5

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.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
5

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
geakie
  • 1,458
  • 9
  • 9
  • finally got the error I had to link "boost_system" to g++ as well from here http://stackoverflow.com/questions/9723793/undefined-reference-to-boostsystemsystem-category-when-compiling. if you are one the mongoDB contributor or know them, just tell them their documents are outdated BIG time! better to change their approach or else they will replaced soon enough. – Vahid Hashemi Sep 14 '12 at 02:22