我阅读了安装指南.
下载安装文件后,为Windows安装OpenSSL库.
从GitHub下载并解压缩了一个Mongo C Driver目录.
从CMake网站下载后安装CMake for Windows .
去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
我从这里下载并打开了cyrus-sasl ,但我坚持了下来.我不知道该怎么做.
如何成功构建MongoDB C驱动程序?
看来 libsasl2 到 Windows 的移植并不完整。虽然我最终编译了 libsasl,但没有生成 libsasl2。MongoDB C Driver for Kerberos 似乎使用 SASL。我不知道他们是否尝试过在没有 libsasl2 库端口的情况下让 Kerberos 在 Windows 上与 C 驱动程序一起工作。
不过,我最终能够编译 MongoDB C 驱动程序。我最初尝试使用 C:\ 的子目录进行编译,而不是 C:\mongo-c-driver 等,但这效果不佳,但是当我使用文档中的目录结构进行编译时,编译成功了。
为了让它编译,我在编译中禁用了 SASL 库。我认为除非您需要使用 Kerberos,否则不需要它。-DENABLE_SASL=no我最初必须显式禁用 SASL(可能是因为使用 64 位)——这可以在编译 mongo-c-driver 时完成。
步骤如下:
从此页面获取驱动程序源: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".
Run Code Online (Sandbox Code Playgroud)
结果发现 C 编译器没有随 Visual Studio 标准安装一起安装,因此我必须安装 Visual Studio 的 C++ 组件。我安装了 C++ Common Tools,但没有安装 MFC for 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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
现在 mongo-c-driver 已经构建完成。我可以将它与 Visual C++ 结合使用,通过 ssl 连接到我的 MongoDB 服务器。
现在,我正在尝试弄清楚如何让 Embarcadero RADStudio C++ Builder 使用新的 mongo-c-driver。仅将 .dll 复制到应用程序的文件夹中就会导致 bson dll 中止。堆栈跟踪如下所示:
| 归档时间: |
|
| 查看次数: |
2631 次 |
| 最近记录: |