如何为Ubuntu安装MongoDB C ++驱动程序? [英] How to install MongoDB C++ drivers for Ubuntu?

查看:240
本文介绍了如何为Ubuntu安装MongoDB C ++驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载了最新的MongoDB C ++驱动程序, http ://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-2.5.2.tgz . 当我做"scons"时,它就好了.建设完成后,我将得到以下信息:

I have downloaded the latest MongoDB C++ driver, http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-2.5.2.tgz. When I do 'scons', it builds just fine. Once the building is complete, I am getting the following:

ranlib build/libmongoclient.a
Install file: "build/libmongoclient.a" as "libmongoclient.a"
scons: done building targets.

它说它安装了mongo,但我想将lib和标头安装在适当的位置,例如/usr/local.不管我尝试什么(scons安装,带或不带--prefix),它都只是不想将其安装在/usr/local中.实际上,它表示安装目标是最新的:

It says it installs mongo, but I would like to install the lib and the headers in a proper place, like /usr/local. No matter what I try (scons install, with or without --prefix), it just doesn't want to install it in /usr/local. In fact, It says that the install target is up to date:

$sudo scons install --prefix=/usr/local
scons: Reading SConscript files ...
Checking for C++ library boost_thread-mt... (cached) yes
Checking for C++ library boost_filesystem-mt... (cached) yes
Checking for C++ library boost_system-mt... (cached) yes
Checking for sasl_version_info(0, 0, 0, 0, 0, 0) in C library sasl2... (cached) yes
Checking for C++ header file execinfo.h... (cached) yes
Checking whether backtrace is declared... (cached) yes
Checking whether backtrace_symbols is declared... (cached) yes
Checking whether backtrace_symbols_fd is declared... (cached) yes
scons: done reading SConscript files.
scons: Building targets ...
scons: `install' is up to date.
scons: done building targets.

我应该使用其他参数来安装它吗?对于该库,我可以复制它,但是要手动安装标头会比较繁琐.

Should i maybe use other parameters to install it? For the library, I can just copy it, but the headers would be more tedious to install manually.

推荐答案

EDIT :此发布吸引了大量访问量,但描述了如何构建现已正式过期的旧版C ++"驱动程序.旧版C ++驱动程序已被新的C ++ 11驱动程序淘汰.当用C ++编写将与MongoDB通信的客户端应用程序时,新的C ++ 11驱动程序应该是首选.有关如何构建新的C ++ 11驱动程序的信息,请参见:

EDIT: This posting gets a lot of traffic, but describes how to build the now-officially-out-of-date "Legacy C++" Driver. The Legacy C++ driver has been obsoleted by the new C++11 driver. The new C++11 driver should be the first choice when writing a client application in C++ that will communicate with MongoDB. Information on how to build the new C++11 driver is available here:

https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(新驱动程序)

编辑:请注意,此答案已过时.泰勒(Tyler)的答案是所有C ++驱动程序现代用户的正确答案.

EDIT: Please note that this answer is obsolete. Tyler's answer below is the correct answer for all modern users of the C++ driver.

我建议您不要尝试使用2.5发行版(或在2.4发行版中)的C ++驱动程序压缩包来构建驱动程序库.

I recommend against trying to use the C++ driver tarball from the 2.5 release (or, for that matter, in the 2.4 release) to build the driver library.

构建C ++驱动程序的最佳方法是从完整的mongodb源档案中获取.造成这种情况的原因有很多,但最重要的是,tarball构建仅提供了非常少的构建系统.如您所见,它没有安装"目标.另一个限制是,tarball构建无法产生共享对象,而完整的源却可以.

The best way to build the C++ driver is from the complete mongodb source archive. There are several reasons for this, but the most important is that the tarball build offers only a very minimal build system. As you noticed, it has no 'install' targets. Another limitation is that the tarball build cannot produce a shared object, while the full sources can.

以下是从主要mongodb来源构建C ++驱动程序的一些基本说明:

Here are some basic instructions on building the C++ driver from the primary mongodb sources:

  • https://github.com/mongodb/mongo
  • 克隆mongodb源
  • 运行scons --prefix=<path-to-install> --full --use-system-all install-mongoclient
  • 如果要共享库(最新版本2.4和最新版本2.5支持),请在上面的行中添加--sharedclient.
  • 如果要调试该库,请传递--dd(2.4)或--dbg=on(主干2.5小费).
  • Clone the mongodb sources from https://github.com/mongodb/mongo
  • Run scons --prefix=<path-to-install> --full --use-system-all install-mongoclient
  • If you want a shared library (supported in latest 2.4, and latest 2.5), add --sharedclient to the line above.
  • If you want a debug build of the library, pass either --dd (2.4), or --dbg=on (2.5 tip of trunk).

--use-system-all标志非常重要:使用它会禁止针对主要mongodb源随附的boost和pcre等版本的供应商进行构建.您不希望您的库是针对那些库构建的,因为生成的库不适合与针对那些库的系统版本构建的应用程序混合使用.当使用--sharedclient进行构建时,这一点尤其重要.

The --use-system-all flag is very important: using it inhibits building against the vendored in versions of things like boost and pcre that come with the primary mongodb sources. You do not want your library to build against those libraries, since the resulting library will not be appropriate to mix with applications built against the system versions of those libraries. This is particularly important when building with --sharedclient.

上述问题的一个挑战是,在使用--use-system-all进行构建时,构建系统会检查系统上是否存在各种库.其中某些库(例如v8)可能不可用.在2.4上,您必须安装该库的适用版本,或编辑SConstruct以禁止查找该库的CheckLib调用.在2.5上,这不是问题,因为如果您尝试构建依赖于缺少库的目标,则缺少库只会导致构建失败.由于构建C ++客户端驱动程序仅依赖少量的库(例如boost),因此上手起来要容易得多.

One challenge with the above is that when building with --use-system-all, the build system checks for the presence of various libraries on the system. Some of these libraries, like v8, may not be available. On 2.4, you must either install an applicable version of the library, or edit the SConstruct to inhibit the CheckLib calls that look for the library. On 2.5, this is not an issue as missing libraries only cause the build to fail if you try to build a target that depends on the missing library. Since building the C++ client driver only depends on a small number of libraries (like boost), it is much easier to get working.

我还建议先使用测试--prefix参数进行构建,以确保安装操作符合您的预期.

I also recommend building with a test --prefix argument first to ensure that the installation actions are as you intend.

希望这会有所帮助.

这篇关于如何为Ubuntu安装MongoDB C ++驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆