简体   繁体   English

在OS X中构建和安装MongoDB C ++驱动程序

[英]Building and installing MongoDB C++ driver in OS X

I have downloaded the latest version of MongoDB C++ driver for my os x from http://dl.mongodb.org/dl/cxx-driver . 我从http://dl.mongodb.org/dl/cxx-driver下载了我的os x的最新版MongoDB C ++驱动程序。 Then I extracted using tar xvf command in os x terminal. 然后我在os x终端中使用tar xvf命令解压缩。 After that I run scons to build the driver. 之后我运行scons来构建驱动程序。 It build successfully by giving following messages 它通过提供以下消息成功构建

-- some messages --
ranlib build/libmongoclient.a
ranlib: file: build/libmongoclient.a(backtrace.o) has no symbols
ranlib: file: build/libmongoclient.a(posix_fadvise.o) has no symbols
ranlib: file: build/libmongoclient.a(ssl_manager.o) has no symbols
Install file: "build/libmongoclient.a" as "libmongoclient.a"
scons: done building targets.

So, then I run the command "scons install" to install the library into my machine. 那么,我运行命令“scons install”将库安装到我的机器中。

--some messages --
scons: done reading SConscript files.
scons: Building targets ...
scons: `install' is up to date.
scons: done building targets.

But when I check into the /usr/local directory for the libmongoclient libs, It's not there. 但是当我在/ usr / local目录中检查libmongoclient库时,它不在那里。 But inside my extracted mongoDB driver folder, there is a file with the name of "libmongoclient.a". 但是在我提取的mongoDB驱动程序文件夹中,有一个名为“libmongoclient.a”的文件。 But there is no file with the extension of ".dylib". 但是没有扩展名为“.dylib”的文件。 Then How do I use mongoDB Xcode & gcc C++ ? 那么我如何使用mongoDB Xcode和gcc C ++? Somebody help me to link with "libmongoclient" library from Xcode. 有人帮我链接Xcode的“libmongoclient”库。

It took me a while to get this working. 我需要一段时间才能完成这项工作。 Hopefully you can get yours working from the following steps: 希望您可以通过以下步骤使您的工作:

Create a new C++ project in Xcode 在Xcode中创建一个新的C ++项目

I copied the code from <mongo_driver_install>/src/mongo/client/examples/tutorial.cpp as a test 我复制了来自<mongo_driver_install>/src/mongo/client/examples/tutorial.cpp的代码作为测试

In Build Settings/Search Paths: 在构建设置/搜索路径中:

搜索路径的屏幕截图

Add the following to your Header Search Paths : 将以下内容添加到Header Search Paths

/path/to/mongo-cxx-driver-nightly/src

and your equivalent path for the boost library header files (the folder should contain a boost folder): 和你的升级库头文件的等效路径(该文件夹应包含一个boost文件夹):

/usr/local/Cellar/boost/1.54.0/include

Add the following to your Library Search Paths : 将以下内容添加到您的Library Search Paths

/usr/local/lib (in my case holds all of the boost libraries)
/path/to/mongo-cxx-driver-nightly

Link Binaries 链接二进制文件

In the Build Phases/Link Binary with Libraries settings: Build Phases/Link Binary with Libraries设置中:

构建阶段的屏幕截图

Add the following binaries: 添加以下二进制文件:

/path/to/mongo-cxx-driver-nightly/libmongoclient.a
/usr/local/lib/libboost_thread-mt.dylib
/usr/local/lib/libboost_system-mt.dylib
/usr/local/lib/libboost_filesystem-mt.dylib
/usr/local/lib/libboost_program_options-mt.dylib

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

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