简体   繁体   English

如何在ubuntu中安装c ++的mongodb驱动程序?

[英]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 我想使用c ++为mongoDB开发一个相当简单的应用程序,我按照他们的教程: 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) 并安装驱动程序我遵循这一个: 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 致命错误:client / dbclient.h:没有这样的文件或目录

I'm pretty sure the problem is MongoDB c++ driver hasn't installed yet. 我很确定问题是MongoDB c ++驱动程序尚未安装。

How can I install it properly? 我该如何正确安装?

In Ubuntu packages for development are separate from packages for general use. 在Ubuntu中,开发包与通用包是分开的。

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. 为了使用mongodb头文件和clientlibraries,你需要sudo apt-get install mongodb-dev libmongo-client-dev - 这会添加标题,允许你#include相关的头文件。

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. 这假设您已经安装了包含客户端库的libmongo-clientmongodb软件包,但是在安装-dev软件包时应该安装它们。

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构建

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. 然后要编译教程中显示的代码,您还需要将/ usr / local / include / mongo目录指定为包含文件搜索路径。

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 然后要运行它,您需要编辑/etc/ld.so.conf文件

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. 作为编辑ld.so.config文件的替代方法,您可以使用LD_LIBRARY_PATH环境变量。 So you would do 所以你会这样做

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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