首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Windows环境下构建MongoDB C驱动程序

在Windows环境下构建MongoDB C驱动程序
EN

Stack Overflow用户
提问于 2016-05-22 16:13:35
回答 4查看 3.5K关注 0票数 6

到目前为止,我所做的

我读过the installation guide

已在下载a setup file后安装适用于Windows的OpenSSL库。

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

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 "Visual Studio14 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驱动程序?

EN

回答 4

Stack Overflow用户

发布于 2016-07-09 15:56:41

到Windows的libsasl2端口似乎没有完成。虽然我最终让libsasl进行了编译,但并没有生成libsasl2。MongoDB C驱动程序似乎使用了SASL。我不知道他们是否试图让Kerberos在没有libsasl2库移植的情况下在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命令提示符,从以管理员身份运行开始

代码语言:javascript
复制
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++组件。我安装了MFC,但没有安装支持C++或XP的C++。也就是说,它将使用3 GB的磁盘空间(从39.5开始,到37.0结束,因此使用了2.5 GB )

安装完成后:

代码语言:javascript
复制
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,我允许Windows将二进制文件安装到OpenSSL系统目录中

现在,

代码语言:javascript
复制
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++中使用它来连接到我的MongoDB服务器。

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

票数 4
EN

Stack Overflow用户

发布于 2017-07-21 01:49:58

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

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

代码语言:javascript
复制
-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“,然后:

代码语言:javascript
复制
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
票数 3
EN

Stack Overflow用户

发布于 2020-02-05 22:39:58

使用当前的Visual Studio,您只需打开项目,构建所有并获取您的all。

  • 我使用了社区2019
  • 确保安装了C++工作负载的桌面开发,它包括CMake support
  • 选择打开,CMake,然后从解压的源归档文件的根目录中选择CMakeLists.txt

现在您已经准备好“全部构建”,但是由于不推荐使用默认的调试构建,您应该打开CMake设置,使用绿色的"+“按钮并选择x86-Release (如果需要,也可以选择x64 )。

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37372007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档