问题
I'm trying to build the mongo-cxx-driver for use with Cinder on Windows 10 with Visual Studio 2015. Cinder uses Boost 1.58, so I built the driver against their included version of Boost.
I tried to follow the instructions exactly as described on github, but the final libs and dlls I get seem to have an issue with them. I'd love some help debugging where my compilation went wrong!
Here's what I did, mirroring the official instructions here
Step 1
I followed the instuctions here for installing the MongoDB C Driver. Simply copy/pasting the CMake calls under the Windows Build Instructions worked perfectly.
Step 2
Since I'm using Windows and Visual Studio 2015, I should use the Boost option for Polyfill.
Step 3
I untarred the mongo-cxx-driver-3.0.2 that I downloaded from github; then I went into mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2
and ran CMake:
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver -DLIBBSON_DIR=C:\mongo-c-driver -DBoost_INCLUDE_DIR=C:\Cinder\include\ -DLIBMONGOC_DIR=C:\mongo-c-driver -DBSONCXX_POLY_USE_BOOST=1 ..
And then built and installed the project:
msbuild.exe ./ALL_BUILD.vcxproj
msbuild.exe ./INSTALL.vcxproj
Everything runs great and I get confirmation from CMake that there were no errors. Hooray!
Issues
While testing, I tried running the test program
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int, char**) {
std::printf("Starting mongo-cxx-driver test...\n");
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
bsoncxx::builder::stream::document document{};
auto collection = conn["testdb"]["testcollection"];
document << "hello" << "world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
std::printf("End of demo!\n");
}
If I run it in Debug, then it crashes after printing out the database with a "Debug Assertion Failed" message:
File: minkernel/crts/ucrt/src/appcrt/heap/debug_heap.cpp
Line: 980
Expression: __acrt_first_block == header
Checking the breakpoint shows that it causes the error on the line at the end of the file -- probably during cleanup from the line
std::cout << bsoncxx::to_json(doc) << std::endl
My first suspicion was that perhaps the .lib files and .dll were built for release -- so I built it in release.
I get an error mongo_test.exe has triggered a breakpoint
with the breakpoint deep inside of bsoncxx.dll!bsoncxx::v_noabi::string::view_or_value::terminated()
.
While trying to debuge, I change the insertion line to:
mongocxx::result::insert_one result = collection.insert_one(document.view());
in an effort to collect more debug information. I was surprised to find that this won't compile with a C2440 error:
'initializing': cannot convert from 'boost::optional<mongocxx::v_noabi::result::insert_one>' to 'mongocxx::v_noabi::result::insert_one' mongo_test C:\mongo_test\src\mongo_testApp.cpp 39
I suspect that perhaps the problem is with how I've linked Boost / std::experimental, but I've tried a couple of different variations (disabling using boost and using std::experimental for polyfill instead), but that doesn't seem to create a working library. Or perhaps there's a mismatch with Debug / Release or x64 vs x86?
Can anyone identify a misstep in this build process?
thanks!
[EDIT] Ran the included tests in mongo-cxx-driver, including the output here for debugging purposes:
~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2> MSBuild.exe .\RUN_TESTS.vcxproj
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 10/12/2016 3:03:11 PM.
Project "~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj" on node 1 (default targets).
Project "~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj" (1) is building "~\Downloads\mongo-cxx-dr
iver-r3.0.2\mongo-cxx-driver-r3.0.2\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
InitializeBuildStatus:
Creating "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
All outputs are up-to-date.
FinalizeBuildStatus:
Deleting file "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
Done Building Project "~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\ZERO_CHECK.vcxproj" (default targets).
PrepareForBuild:
Creating directory "x64\Debug\RUN_TESTS\".
Creating directory "x64\Debug\RUN_TESTS\RUN_TESTS.tlog\".
InitializeBuildStatus:
Creating "x64\Debug\RUN_TESTS\RUN_TESTS.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
PostBuildEvent:
setlocal
"C:\Program Files\CMake\bin\ctest.exe" --force-new-ctest-process -C Debug
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd
Test project C:/Users/nathan lachenmyer/Downloads/mongo-cxx-driver-r3.0.2/mongo-cxx-driver-r3.0.2
Start 1: bson
1/3 Test #1: bson .............................***Exception: Other 0.00 sec
Start 2: driver
2/3 Test #2: driver ...........................***Exception: Other 0.01 sec
Start 3: instance
3/3 Test #3: instance .........................***Exception: Other 0.00 sec
0% tests passed, 3 tests failed out of 3
Errors while running CTest
Total Test time (real) = 0.03 sec
The following tests FAILED:
1 - bson (OTHER_FAULT)
2 - driver (OTHER_FAULT)
3 - instance (OTHER_FAULT)
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: The command "setlocal\r [~\Downloads\mongo-cxx-d
river-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: "C:\Program Files\CMake\bin\ctest.exe" --force-new-ctest-process -C Debug
\r [~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd\r [~\Downloads
\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmEnd\r [~\Downloads\mongo-cxx-driver-r3.0.2\mo
ngo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone\r [C:\Users\nat
han lachenmyer\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmErrorLevel\r [~\Downloads\mongo-cxx-driver-r3
.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: exit /b %1\r [~\Downloads\mongo-cxx-driver-r3.0.
2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmDone\r [~\Downloads\mongo-cxx-driver-r3.0.2\m
ongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd\r [~\Downloads
\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :VCEnd" exited with code 8. [~\Downloads\mongo-c
xx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
Done Building Project "~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj" (default targets) -- FAILED.
Build FAILED.
"~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj" (default target) (1) ->
(PostBuildEvent target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: The command "setlocal\r [~\Downloads\mongo-cxx
-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: "C:\Program Files\CMake\bin\ctest.exe" --force-new-ctest-process -C Debug
\r [~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd\r [~\Downloads
\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmEnd\r [~\Downloads\mongo-cxx-driver-r3.0.2\mo
ngo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone\r [C:\Users\nat
han lachenmyer\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmErrorLevel\r [~\Downloads\mongo-cxx-driver-r3
.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: exit /b %1\r [~\Downloads\mongo-cxx-driver-r3.0.
2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmDone\r [~\Downloads\mongo-cxx-driver-r3.0.2\m
ongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd\r [~\Downloads
\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(133,5): error MSB3073: :VCEnd" exited with code 8. [~\Downloads\mongo-c
xx-driver-r3.0.2\mongo-cxx-driver-r3.0.2\RUN_TESTS.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.71
来源:https://stackoverflow.com/questions/39982310/mongo-cxx-driver-library-builds-but-persistent-linking-and-debug-issues