在Windows中构建MongoDB C驱动程序 [英] Building MongoDB C Driver in Windows
问题描述
我阅读了安装指南.
下载安装文件后,为Windows安装了OpenSSL库.
Installed OpenSSL library for Windows after downloading a setup file.
从 GitHub 下载并提取Mongo C驱动程序目录.
Downloaded and extracted a Mongo C Driver directory from GitHub.
从 CMake网站下载后,为Windows安装了CMake.
Installed CMake for Windows after downloading from CMake web site.
进入mongo-c-driver/src/libbson
并运行cmake -G "Visual Studio 14 2015 Win64"
,它会打印(也许)成功.
Went to mongo-c-driver/src/libbson
and run cmake -G "Visual Studio 14 2015 Win64"
and it prints (maybe) success.
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
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"并打印出这样的错误.
Went to mongo-c-driver
and run `cmake -G "Visual Studio 14 2015 Win64" and prints errors like this.
-- 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".
-- 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
I looked for sasl.h
from my disks but there is none. I also looked for it from OpenSSL GitHub but it does not have sasl.h
我从此处下载并打开了cyrus-sasl,但我遇到了麻烦用它.我不知道该怎么办.
I downloaded and opened cyrus-sasl from here, but I am stuck with it. I don't know what to do with it.
如何成功构建MongoDB C驱动程序?
How can I do the successful build of MongoDB C Driver?
推荐答案
Windows的libsasl2端口似乎不完整.尽管最终我确实编译了libsasl,但没有产生libsasl2.看来MongoDB C驱动程序已将SASL用于Kerberos.我不知道他们是否试图在没有libsasl2库端口的情况下使Kerberos与Windows上的C驱动程序一起使用.
It appears that the libsasl2 port to Windows is not complete. Although I did ultimately get libsasl to compile, there was no libsasl2 produced. It appears that SASL is used by MongoDB C Driver for Kerberos. I don't know if they have tried to get Kerberos working with the C Driver on Windows without a port of the libsasl2 library.
但是,我能够使MongoDB C驱动程序最终得以编译.最初,我尝试使用C:\的子目录进行编译,而不是使用C:\ mongo-c-driver等,但是效果并不理想,但是当我使用文档中的目录结构进行编译时,编译成功了.
I was, however, able to get the MongoDB C Driver to ultimately compile. I initially tried to compile using subdirectories of C:\, as opposed to C:\mongo-c-driver etc., but that didn't work well, but when I compiled using the directory structure in the documentation, the compile succeeded.
要使其编译,我在编译中禁用了SASL库.我认为除非您需要使用Kerberos,否则不需要它.最初,我不得不显式禁用SASL(可能是因为使用64位),这可以在编译mongo-c-driver时使用-DENABLE_SASL=no
来完成.
To get it to compile, I disabled the SASL library in the compilation. I don't think it will be needed unless you need to use Kerberos. I initially had to explicitly disable SASL (perhaps because of using 64 bit) -- that can be done with -DENABLE_SASL=no
when compiling the mongo-c-driver.
以下是步骤:
此页面上的驱动程序源: https://github.com/mongodb/mongo-c-driver/releases (1.3.5)
Got driver source from this page: https://github.com/mongodb/mongo-c-driver/releases (1.3.5)
使用Windows安装程序安装了cmake,将cmake添加到所有用户的路径中.我必须注销并重新登录才能获取更新路径.
Installed cmake using the Windows installer, adding cmake to the path for all users. I had to log out and log back in to get the path to update.
然后,我将mongo-c-driver-1.3.5源复制到c:\ mongo-c-driver-1.3.5
Then, I copied the mongo-c-driver-1.3.5 source to c:\mongo-c-driver-1.3.5
然后
我使用了以以管理员身份运行"开始的Visual Studio MSBuild命令提示符
I used the Visual Studio MSBuild Command Prompt, started with Run As Administrator
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".
结果表明,标准的Visual Studio安装未安装C编译器,因此我必须安装Visual Studio的C ++组件.我安装了C ++通用工具,但没有安装MFC for C ++或XP Support.也就是说,它将使用3 GB的磁盘空间(开始于39.5,结束于37.0,因此使用了2.5 GB)
Turns out that the C compilers are not installed with a standard installation of Visual Studio, so I had to install C++ component of Visual Studio. I installed C++ Common Tools, but not MFC for C++ nor XP Support. That said it would use 3 GB of disk space (started at 39.5, ended at 37.0, so 2.5 GB used)
一旦安装:
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://获得了32位Win32 OpenSSL v1.0.2h slproweb.com/products/Win32OpenSSL.html
OpenSSL was not present, so I obtained 32 bit Win32 OpenSSL v1.0.2h from http://slproweb.com/products/Win32OpenSSL.html
然后,我安装了OpenSSL.将安装目录更改为C:\ work \ OpenSSL-Win32,并且我允许OpenSSL安装程序将二进制文件安装到Windows系统目录中
Then, I installed OpenSSL. Changed installation directory to C:\work\OpenSSL-Win32, and I allowed the OpenSSL installer to install the binaries into the Windows system directory
现在
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服务器.
And now the mongo-c-driver has been built. I can use it with Visual C++ to connect to my MongoDB server using ssl.
现在,我正在尝试弄清楚如何使Embarcadero RADStudio C ++ Builder能够使用新的mongo-c-driver.仅将.dll复制到应用程序的文件夹中会导致bson dll中止.堆栈跟踪如下所示:
Now, I am trying to figure out how to get Embarcadero RADStudio C++ Builder to use the new mongo-c-driver. Just copying the .dll's into the application's folder results in an abort in the bson dll. The stack trace looks like this:
这篇关于在Windows中构建MongoDB C驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!