在Windows中构建MongoDB C驱动程序

时间:2016-05-22 08:13:35

标签: mongodb

到目前为止我做了什么

我看了the installation guide

下载a setup file后,为Windows安装了OpenSSL库。

GitHub下载并解压缩Mongo C驱动程序目录。

CMake web site下载后安装了适用于Windows的CMake。

mongo-c-driver/src/libbson并运行cmake -G "Visual Studio 14 2015 Win64"并打印(可能)成功。

D:\works\test\mongo-c-driver\src\libbson>cmake -G "Visual Studio 14 2015 Win64" Current version (from VERSION_CURRENT file): 1.4.0-dev Previous release (from VERSION_RELEASED file): 1.3.5 -- Check if the system is big endian -- Searching 16 bit integer -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of unsigned short -- Check size of unsigned short - done -- Using unsigned short -- Check if the system is big endian - little endian -- Looking for snprintf -- Looking for snprintf - found -- Looking for _set_output_format -- Looking for _set_output_format - not found -- Performing Test BSON_HAVE_TIMESPEC -- Performing Test BSON_HAVE_TIMESPEC - Success -- struct timespec found -- Configuring done -- Generating done -- Build files have been written to: D:/works/test/mongo-c-driver/src/libbson

执行msbuild ALL_BUILD.vcxproj并打印成功。

问题

mongo-c-driver并运行`cmake -G" Visual Studio 14 2015 Win64"并打印出这样的错误。

-- Found BSON: BSON-NOTFOUND;ws2_32
-- Found OpenSSL: optimized;D:/apps/OpenSSL-Win64/lib/VC/ssleay32MD.lib;debug;D:/apps/OpenSSL-Win64/lib/VC/ssleay32MDd.lib;optimized;D:/apps/OpenSSL-Win64/lib/VC/libeay32MD.lib;debug;D:/apps/OpenSSL-Win64/lib/VC/libeay32MDd.lib (found version "1.0.2h") -- Searching for sasl/sasl.h -- Not found (specify -DCMAKE_INCLUDE_PATH=C:/path/to/sasl/include for SASL support) -- Searching for libsasl2 -- Not found (specify -DCMAKE_LIBRARY_PATH=C:/path/to/sasl/lib for SASL support) -- Configuring incomplete, errors occurred! See also "D:/works/test/mongo-c-driver/CMakeFiles/CMakeOutput.log".

我从我的磁盘中查找了sasl.h,但没有。我也从OpenSSL GitHub查找它,但它没有sasl.h

我从here下载并打开了cyrus-sasl,但我坚持了下来。我不知道该怎么做。

如何成功构建MongoDB C驱动程序?

4 个答案:

答案 0 :(得分:4)

似乎Windows的libsasl2端口不完整。虽然我最终得到libsasl进行编译,但没有生成libsasl2。似乎SASL被MongoDB C Driver用于Kerberos。我不知道他们是否曾尝试在没有libsasl2库的端口的情况下让Kerberos在Windows上使用C驱动程序。

但是,我能够让MongoDB C驱动程序最终编译。我最初尝试使用C:\的子目录进行编译,而不是C:\ mongo-c-driver等,但这并没有很好地工作,但是当我使用文档中的目录结构进行编译时,编译成功了。

为了让它编译,我在编译中禁用了SASL库。除非您需要使用Kerberos,否则我认为不需要它。我最初必须明确禁用SASL(可能是因为使用64位) - 在编译mongo-c-driver时可以使用-DENABLE_SASL=no来完成。

以下是步骤:

从此页面获取驱动程序源:https://github.com/mongodb/mongo-c-driver/releases(1.3.5)

来自https://cmake.org/download/

的cmake

使用Windows安装程序安装cmake,将cmake添加到所有用户的路径中。我不得不退出并重新登录以获取更新路径。

然后,我将mongo-c-driver-1.3.5源复制到c:\ mongo-c-driver-1.3.5

然后,

我使用Visual Studio MSBuild命令提示符,以“以管理员身份运行”

启动
C:\mongo-c-driver-1.3.5\src\libbson>cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -G "Visual Studio 14"
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_CXX_COMPILER could be found.

-- Configuring incomplete, errors occurred!
See also "C:/mongo-c-driver-1.3.5/src/libbson/CMakeFiles/CMakeOutput.log".
See also "C:/mongo-c-driver-1.3.5/src/libbson/CMakeFiles/CMakeError.log".

事实证明C编译器没有安装Visual Studio的标准安装,所以我不得不安装Visual Studio的C ++组件。我安装了C ++通用工具,但没有安装CFC用于C ++和XP支持。那说它将使用3 GB的磁盘空间(从39.5开始,以37.0结束,因此使用2.5 GB)

安装完成后:

cd \mongo-c-driver-1.3.5\src\libbson
cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -G "Visual Studio 14" .
msbuild.exe ALL_BUILD.vcxproj
msbuild.exe INSTALL.vcxproj
cd ..\..

C:\mongo-c-driver-1.3.5>cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -DENABLE_SSL=WINDOWS -DBSON_ROOT_DIR=C:\libmongoc -G "Visual Studio 14" .
-- The C compiler identification is MSVC 19.0.23026.0
-- The CXX compiler identification is MSVC 19.0.23026.0
-- Check for working C compiler using: Visual Studio 14 2015
-- Check for working C compiler using: Visual Studio 14 2015 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 14 2015
-- Check for working CXX compiler using: Visual Studio 14 2015 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found BSON: C:/libmongoc/lib/bson-1.0.lib;ws2_32
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing:  OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR)
-- Searching for sasl/sasl.h
--   Not found (specify -DCMAKE_INCLUDE_PATH=C:/path/to/sasl/include for SASL support)
-- Searching for libsasl2
--   Not found (specify -DCMAKE_LIBRARY_PATH=C:/path/to/sasl/lib for SASL support)
Current version (from VERSION_CURRENT file): 1.3.5
-- Configuring done
-- Generating done
-- Build files have been written to: C:/mongo-c-driver-1.3.5

OpenSSL不存在,所以我从http://slproweb.com/products/Win32OpenSSL.html获得了32位Win32 OpenSSL v1.0.2h

然后,我安装了OpenSSL。将安装目录更改为C:\ work \ OpenSSL-Win32,并允许OpenSSL安装程序将二进制文件安装到Windows系统目录中

现在,

C:\mongo-c-driver-1.3.5>cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -DENABLE_SSL=WINDOWS -DBSON_ROOT_DIR=C:\libmongoc -G "Visual Studio 14" .
-- Found OpenSSL: optimized;C:/work/OpenSSL-Win32/lib/VC/ssleay32MD.lib;debug;C:/work/OpenSSL-Win32/lib/VC/ssleay32MDd.lib;optimized;C:/work/OpenSSL-Win32/lib/VC/libeay32MD.lib;debug;C:/work/OpenSSL-Win32/lib/VC/libeay32MDd.lib (found version "1.0.2h")
-- Searching for sasl/sasl.h
--   Not found (specify -DCMAKE_INCLUDE_PATH=C:/path/to/sasl/include for SASL support)
-- Searching for libsasl2
--   Not found (specify -DCMAKE_LIBRARY_PATH=C:/path/to/sasl/lib for SASL support)
Current version (from VERSION_CURRENT file): 1.3.5
-- Configuring done
-- Generating done
-- Build files have been written to: C:/mongo-c-driver-1.3.5

C:\mongo-c-driver-1.3.5>

msbuild.exe ALL_BUILD.vcxproj
(lots of output, with some yellow warnings, but no red errors)

msbuild.exe INSTALL.vcxproj

现在已经建立了mongo-c-driver。我可以使用它与Visual C ++使用ssl连接到我的MongoDB服务器。

现在,我想弄清楚如何让Embarcadero RADStudio C ++ Builder使用新的mongo-c-driver。只需将.dll复制到应用程序的文件夹中就会导致bson dll中止。堆栈跟踪如下所示:

Screenshot showing stack trace

答案 1 :(得分:3)

该输出中有两个错误。 - 必须安装并提供libbson - mongoc是针对cyrus sasl配置的,在这种情况下必须安装并且可用

两者都很容易修复,如果cyrus sasl或openssl不可用,mongoc的更高版本将不再出错,而是使用Windows本机实现。也可以在没有它们的情况下配置驱动程序 可用的配置选项和值包括:

-DENABLE_SASL=[CYRUS|SSPI|AUTO|OFF]
-DENABLE_SSL=[OPENSSL|WINDOWS|DARWIN|AUTO|OFF]

不幸的是,mongoc的cmake安装不会自动安装捆绑的libbson,将来可能会修复,但是现在你需要单独安装它。

简而言之,要在Windows上安装mongoc驱动程序:

下载&提取mongoc(https://github.com/mongodb/mongo-c-driver/releases)。 mongoc版本附带libbson源代码,因此无需单独下载它们。 进入libbson目录," src / libbson"然后:

cd c:/path/to/mongoc/
cd src/libbson

# Configure and install libbson
cmake.exe -G "Visual Studio 14 2015 Win64" \
    -DCMAKE_INSTALL_PREFIX=c:/mongoc
msbuild.exe ALL_BUILD.vcxproj
msbuild.exe INSTALL.vcxproj # Installs libbson

cd ../.. # Go back to the root folder of the release sources

# Configure and install mongoc
cmake.exe -G "Visual Studio 14 2015 Win64" \
    -DCMAKE_INSTALL_PREFIX=c:/mongoc \
    -DCMAKE_PREFIX_PATH=c:/mongoc/lib/cmake \
    -DENABLE_AUTOMATIC_INIT_AND_CLEANUP:BOOL=OFF \
    -DENABLE_SSL=WINDOWS \ # Use Windows Native TLS, rather then OpenSSL
    -DENABLE_SASL=SSPI # Use Windows Native SSPI, rather then Cyrus SASL
msbuild.exe ALL_BUILD.vcxproj
msbuild.exe INSTALL.vcxproj

答案 2 :(得分:1)

使用当前的 Visual Studio ,您可以打开项目,构建所有文件并获取DLL。

  • 我使用了Community 2019
  • 确保已安装带有C ++的台式机开发工作负载,其中包括 CMake 支持
  • 选择 Open CMake ,然后从提取的源档案的根目录中选择 CMakeLists.txt

现在您已经准备好“全部构建”,但是由于不建议使用默认调试版本,因此您应该打开CMake设置,使用绿色的“ +”按钮,然后选择 x86-Release (或 x64 (如果需要)。


对于 Delphi 用户:默认的DLL文件名没有必需的“ lib”前缀(libmongoc-1.0.dll),因此请相应地编辑BSON_OUTPUT_BASENAMEMONGOC_OUTPUT_BASENAME变量

另一个提示:Delphi安装程序在两个位置包含文件: bin&Redist \ win32,bin64&Redist \ win64 -祝您好运!

答案 3 :(得分:-1)

1.17.0-rc0 x86版本驱动程序

https://gofile.io/d/0wJ4R4