mongo-cxx-driver library builds but persistent linking and debug issues
<p>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.</p>

<p>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!</p>

<p>Here's what I did, mirroring the official instructions <a href="https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/" rel="nofollow">here</a></p>

<h2>Step 1</h2>

<p>I followed the instuctions <a href="http://mongoc.org/libmongoc/current/installing.html" rel="nofollow">here</a> for installing the MongoDB C Driver.  Simply copy/pasting the CMake calls under the Windows Build Instructions worked perfectly.</p>

<h2>Step 2</h2>

<p>Since I'm using Windows and Visual Studio 2015, I should use the Boost option for Polyfill.</p>

<h2>Step 3</h2>

<p>I untarred the mongo-cxx-driver-3.0.2 that I downloaded from github; then I went into <code>mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2</code> and ran CMake:</p>

<p><code>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 ..</code></p>

<p>And then built and installed the project:</p>

<pre><code>msbuild.exe ./ALL_BUILD.vcxproj
msbuild.exe ./INSTALL.vcxproj
</code></pre>

<p>Everything runs great and I get confirmation from CMake that there were no errors.  Hooray!</p>

<h2>Issues</h2>

<p>While testing, I tried running the test program</p>

<pre><code>#include &lt;iostream&gt;

#include &lt;bsoncxx/builder/stream/document.hpp&gt;
#include &lt;bsoncxx/json.hpp&gt;

#include &lt;mongocxx/client.hpp&gt;
#include &lt;mongocxx/instance.hpp&gt;

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 &lt;&lt; "hello" &lt;&lt; "world";

    collection.insert_one(document.view());
    auto cursor = collection.find({});

    for (auto&amp;&amp; doc : cursor) {
        std::cout &lt;&lt; bsoncxx::to_json(doc) &lt;&lt; std::endl;
    }
    std::printf("End of demo!\n");
}
</code></pre>

<p>If I run it in Debug, then it crashes after printing out the database with a "Debug Assertion Failed" message:</p>

<pre><code>File: minkernel/crts/ucrt/src/appcrt/heap/debug_heap.cpp
Line: 980
Expression: __acrt_first_block == header
</code></pre>

<p>Checking the breakpoint shows that it causes the error on the line at the end of the file -- probably during cleanup from the line</p>

<pre><code>std::cout &lt;&lt; bsoncxx::to_json(doc) &lt;&lt; std::endl
</code></pre>

<p>My first suspicion was that perhaps the .lib files and .dll were built for release -- so I built it in release.</p>

<p>I get an error <code>mongo_test.exe has triggered a breakpoint</code> with the breakpoint deep inside of <code>bsoncxx.dll!bsoncxx::v_noabi::string::view_or_value::terminated()</code>.</p>

<p>While trying to debuge, I change the insertion line to:</p>

<pre><code>mongocxx::result::insert_one result = collection.insert_one(document.view());
</code></pre>

<p>in an effort to collect more debug information.  I was surprised to find that this won't compile with a C2440 error:</p>

<pre><code>'initializing': cannot convert from 'boost::optional&lt;mongocxx::v_noabi::result::insert_one&gt;' to 'mongocxx::v_noabi::result::insert_one' mongo_test  C:\mongo_test\src\mongo_testApp.cpp 39  
</code></pre>

<p>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?</p>

<p>Can anyone identify a misstep in this build process?</p>

<p>thanks!</p>

<p>[EDIT] Ran the included tests in mongo-cxx-driver, including the output here for debugging purposes:</p>

<pre><code>~\Downloads\mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2&gt; 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 &amp; call :cmErrorLevel %errorlevel% &amp; 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 &amp; call :cmErrorLevel %errorlevel% &amp; 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) -&gt;
(PostBuildEvent target) -&gt;
  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 &amp; call :cmErrorLevel %errorlevel% &amp; 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
</code></pre>