2

我正在尝试遵循本指南,目前处于第 3 步。

所以跑完之后,

curl -OL https://github.com/mongodb/mongo-cxx-driver/archive/r3.0.1.tar.gz
tar -xzf r3.0.1.tar.gz
cd mongo-cxx-driver-r3.0.1/

我尝试执行与mongoc 的 Windows 指南中类似的命令:

如果我只是

cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=C:/mongo-cxx-driver"

我收到一个错误

CMake Error at cmake/FindLibBSON.cmake:37 (message):
  Don't know how to find libbson; please set LIBBSON_DIR to the prefix
  directory with which libbson was configured.
Call Stack (most recent call first):
  src/bsoncxx/CMakeLists.txt:67 (find_package)

所以在这里我尝试了不同的东西,比如将路径添加到 libsson 目录:

cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=C:/mongo-cxx-driver" "-DLIBBSON_DIR=C:/mongo-c-driver/lib/pkgconfig/" "-DLIBMONGOC_DIR=C:/mongo-c-driver/lib/pkgconfig/" "-DBOOST_ROOT=C:/local/boost_1_62_0/"

这实际上有效,但是当我尝试构建时

msbuild.exe ALL_BUILD.vcxproj

我收到一个错误:

C:\Users\Erik\Documents\mongo-cxx-driver-r3.0.1\src\bsoncxx\array\view.cpp(21): fatal error C1083: Cannot open include
 file: 'bson.h': No such file or directory [C:\Users\Erik\Documents\mongocxx-driver-r3.0.1\src\bsoncxx\bsoncxx_static.v
cxproj]

这个文件“bson.h”似乎驻留在目录中

C:\mongo-c-driver\include\libbson-1.0

但我不确定它为什么找不到该文件或我如何才能找到它。

非常感谢您对此的任何意见。

4

2 回答 2

4

您没有LIBBSON_DIR正确设置LIBMONGOC_DIR。在您的情况下,它们应该都设置为C:\mongo-c-driver. 构建系统将根据需要自动添加includelib到该基本路径。您可能会发现阅读 appveyor 脚本信息丰富:

于 2016-10-02T23:32:39.540 回答
0

2016 年 10 月 18 日

这个问题也发生在 Mac OS X 上,也可能发生在其他 Un*xes 上。

  1. 使用版本 3.0.2(至少)。(官方指南提到了3.0.1,但是3.0.2修复了一个bug )。
curl -OL https://github.com/mongodb/mongo-cxx-driver/archive/r3.0.2.tar.gz
  1. 我没有更改build目录,而是更改为根目录:
cd mongo-cxx-driver-r3.0.2 
  1. 如果 C mongo 驱动程序(和 libbson)不在默认目录中,请将其告知 cmake 命令,并说我们采用现代 C++(11、14、...)。就我而言:C mongo 驱动程序位于 /opt/mongodbDriverCpp (放置 C++ mongo 驱动程序的相同位置)。
cmake -DCMAKE_BUILD_TYPE=发布
-DCMAKE_INSTALL_PREFIX=/opt/mongodbDriverCpp
-DLIBBSON_DIR=/opt/mongodbDriverCpp  
-DLIBMONGOC_DIR=/opt/mongodbDriverCpp
-DCMAKE_CXX_STANDARD=14
  1. 制作和安装
制作

进行安装
  1. 从官方指南编译测试的命令(更改/opt/mongodbDriverCpp到您的正确目录):
c++ --std=c++11 test.cpp -o run.test
-I/opt/mongodbDriverCpp/include/bsoncxx/v_noabi
-I /opt/mongodbDriverCpp/include/mongocxx/v_noabi/
-L /opt/mongodbDriverCpp/lib
-l mongocxx
-l bsoncxx
  1. 运行(先启动mongodb服务器)
导出 LD_LIBRARY_PATH=/opt/mongodbDriverCpp/lib

./run.test
于 2016-10-18T08:59:32.360 回答