简体   繁体   English

如何为Ubuntu安装MongoDB C ++驱动程序?

[英]How to install MongoDB C++ drivers for Ubuntu?

I have downloaded the latest MongoDB C++ driver, http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-2.5.2.tgz . 我已经下载了最新的MongoDB C ++驱动程序, http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-2.5.2.tgz When I do 'scons', it builds just fine. 当我做'scons'时,它构建得很好。 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.

It says it installs mongo, but I would like to install the lib and the headers in a proper place, like /usr/local. 它说它安装了mongo,但我想在适当的位置安装lib和头文件,比如/ usr / local。 No matter what I try (scons install, with or without --prefix), it just doesn't want to install it in /usr/local. 无论我尝试什么(scons安装,有或没有--prefix),它只是不想在/ 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. 对于库,我可以复制它,但手动安装标题会更加繁琐。

Currently the best way to install the MongoDB C++ driver is to go to the official github repository and read the "Download and Compile" wiki page . 目前安装MongoDB C ++驱动程序的最佳方法是访问官方github存储库并阅读“下载和编译”维基页面

There are three branches of the repository (two currently offering a stable release stream). 存储库有三个分支(两个目前提供稳定的发布流)。 The first stable release series is named 26compat (MongoDB 2.6 compatible) which has the source code as extracted from the 2.6 release of MongoDB (along with minor modifications to make it independent). 第一个稳定版本系列命名为26compat (MongoDB 2.6兼容),其源代码摘自MongoDB的2.6版本(以及使其独立的微小修改)。 It is intended as a drop in replacement for existing code built around the C++ driver. 它旨在替代围绕C ++驱动程序构建的现有代码。

The other stable release series is named legacy and it is similar to the 26compat branch but contains some backward breaking improvements and many important improvements and fixes. 另一个稳定版本系列名为legacy ,它类似于26compat分支,但包含一些落后的改进和许多重要的改进和修复。 It is the correct starting point for new projects . 这是新项目正确起点 Existing projects using the old "server driver" or the 26compat driver should also aim to upgrade to the stable legacy release series. 使用旧的“服务器驱动程序”或26compat驱动程序的现有项目也应该旨在升级到稳定的旧版本系列。

If you are interested, you can read more about the changes here but in general you will have a better time using what we provide at the github repository now. 如果您有兴趣,可以在这里阅读有关更改的更多信息,但一般情况下,您现在可以更好地使用我们在github存储库中提供的内容。 While the C++ driver was technically available before via the server source it was not really intended to be used external to MongoDB. 虽然C ++驱动程序在通过服务器源之前在技术上可用,但它实际上并不打算在MongoDB外部使用。 Now, the code we are providing at the official repository is intended to be used externally and supported by the C++ driver team. 现在,我们在官方库提供代码目的由C ++的驾驶员队伍,以在外部使用和支持。

We are also working on an entirely new driver built for C++11 on the master branch, but that is not yet production ready. 我们还在为master分支上的C ++ 11构建一个全新的驱动程序 ,但尚未准备好生产。 We encourage you to experiment with it and provide feedback. 我们鼓励您尝试并提供反馈。

EDIT : This posting gets a lot of traffic, but describes how to build the now-officially-out-of-date "Legacy C++" Driver. 编辑 :这个帖子获得了大量的流量,但描述了如何构建现在正式过时的“Legacy C ++”驱动程序。 The Legacy C++ driver has been obsoleted by the new C++11 driver. Legacy C ++驱动程序已被新的C ++ 11驱动程序淘汰。 The new C++11 driver should be the first choice when writing a client application in C++ that will communicate with MongoDB. 在用C ++编写将与MongoDB通信的客户端应用程序时,新的C ++ 11驱动程序应该是首选。 Information on how to build the new C++11 driver is available here: 有关如何构建新C ++ 11驱动程序的信息,请访问:

https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(New-Driver) https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(New-Driver)

EDIT : Please note that this answer is obsolete. 编辑 :请注意,这个答案已经过时了。 Tyler's answer below is the correct answer for all modern users of the C++ driver. Tyler的答案是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. 我建议不要尝试使用2.5版本中的C ++驱动程序tarball(或者,就此而言,在2.4版本中)来构建驱动程序库。

The best way to build the C++ driver is from the complete mongodb source archive. 构建C ++驱动程序的最佳方法是使用完整的mongodb源存档。 There are several reasons for this, but the most important is that the tarball build offers only a very minimal build system. 这有几个原因,但最重要的是tarball构建只提供了一个非常小的构建系统。 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. 另一个限制是tarball构建不能生成共享对象,而完整源可以。

Here are some basic instructions on building the C++ driver from the primary mongodb sources: 以下是从主要mongodb源构建C ++驱动程序的一些基本说明:

  • Clone the mongodb sources from https://github.com/mongodb/mongo https://github.com/mongodb/mongo克隆mongodb源代码
  • Run scons --prefix=<path-to-install> --full --use-system-all install-mongoclient 运行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. 如果您需要共享库(最新2.4和最新2.5支持),请在上面的行中添加--sharedclient
  • If you want a debug build of the library, pass either --dd (2.4), or --dbg=on (2.5 tip of trunk). 如果需要库的调试版本,请传递--dd (2.4)或--dbg=on (2.5 tip of trunk)。

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. --use-system-all标志非常重要:使用它会禁止构建与主要mongodb源附带的boost和pcre等版本相关的内容。 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 . 使用--sharedclient构建时,这一点尤其重要。

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. 上面的一个挑战是,当使用--use-system-all构建时,构建系统会检查系统上是否存在各种库。 Some of these libraries, like v8, may not be available. 其中一些库(如v8)可能无法使用。 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. 在2.4,您必须安装适用版本的库,或编辑SConstruct以禁止查找库的CheckLib调用。 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. 在2.5上,这不是问题,因为如果您尝试构建依赖于缺少的库的目标,则缺少的库只会导致构建失败。 Since building the C++ client driver only depends on a small number of libraries (like boost), it is much easier to get working. 由于构建C ++客户端驱动程序仅依赖于少量库(如boost),因此更容易实现。

I also recommend building with a test --prefix argument first to ensure that the installation actions are as you intend. 我还建议首先使用test --prefix参数构建,以确保安装操作符合您的意图。

Hope this helps. 希望这可以帮助。

Unfortunately the library isn't automatically installed. 不幸的是,库不会自动安装。 It is compiled so you can distribute the library with your application. 它已编译,因此您可以使用您的应用程序分发库。 Including the cpp or using the tarball file isn't recommended. 不建议包括cpp或使用tarball文件。

Please see the documentation at this link: http://docs.mongodb.org/ecosystem/tutorial/download-and-compile-cpp-driver/#download-and-compile-cpp-driver 请参阅此链接中的文档: http//docs.mongodb.org/ecosystem/tutorial/download-and-compile-cpp-driver/#download-and-compile-cpp-driver

Best, Charlie 最好,查理

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

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