C++ Driver builds on Windows, but crashes

510 views
Skip to first unread message

nathan lachenmyer

unread,
Oct 12, 2016, 7:23:22 PM10/12/16
to mongodb-user
I'm trying to build the C++ for use with the Cinder C++ Framework on Windows 10 with Visual Studio 2015.  Cinder uses Boost 1.58, so I built the driver against their included version of Boost to minimize dependency conflicts / issues.

I tried to follow the instructions exactly as described on github, but the final output seems to crash and have issues despite building with no problems.

Here's what I did, mirroring the instructions (https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/)

## Step 1

I followed the instuctions for installing the MongoDB C Driver (http://mongoc.org/libmongoc/current/installing.html).  Simply copy/pasting the CMake calls under the Windows Build Instructions worked perfectly; I compiled v1.3.4 as that's the version the C++ driver says that it needs.

## 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 up to this point.

## 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

Andrew Morrow

unread,
Oct 13, 2016, 12:33:55 PM10/13/16
to mongod...@googlegroups.com

Hi -

I see you moved this from SO here, which is fine. My suspicion here is a mismatch of CRT variants between the Cinder boost libraries and the driver you built. I'd like to perform a few experiments first though, to rule out some other potential causes:

- Can you try building the driver with MNMLSTC and make sure that the tests pass?
- Can you try building against an independently downloaded binary version of boost?

If both of those work, then we can focus on what is unique about the Cinder boost environment, and see how we can convince the C++ driver to work with it correctly.

Thanks,
Andrew




--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/6a9ac24e-2d54-450f-9fdf-55afed28f971%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nathan lachenmyer

unread,
Oct 13, 2016, 2:46:16 PM10/13/16
to mongodb-user
I downloaded Boost 1.58 from the boost website to compile against (I also used the -DCMAKE_BUILD_TYPE=Debug flag just to be safe, to make sure everything came out in Debug).  I ended up with the exact same errors.

I'm not sure how to building the driver with MNMLSTC -- can you elaborate as to how that would work?

nathan
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

Andrew Morrow

unread,
Oct 13, 2016, 2:48:31 PM10/13/16
to mongod...@googlegroups.com

To build the driver with MNMLSTC, you can just not specify any polyfill option (MNMLSTIC is the default).

To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.

nathan lachenmyer

unread,
Oct 13, 2016, 3:38:51 PM10/13/16
to mongodb-user
Hmm.

I compiled it twice against Boost 1.58 and Boost 1.62 straight from their site without any polyfill options, and it gives me the exact same errors -- running RUN_TESTS.vcxproj also gives me the same errors.

nathan

Andrew Morrow

unread,
Oct 19, 2016, 10:57:39 AM10/19/16
to mongod...@googlegroups.com

Hi - 

Apologies for the delay getting back to you. Right now, I'm not sure what is causing the problems you have reported. I think we should step back and try to document in extreme and boring detail each step you have taken, so we can try to form some new hypotheses as to what is going wrong. Apologies for the long list of questions!

- What version, exactly, of Visual Studio are you using?
- What version of the C driver are you using (git hash)?
- What was the CMake invocation you used to generate the build system for the C driver?
- What was the msbuild or CMake invocation you used to build the C driver?
- What CRT is the C driver built against? (Debug vs Release and Static vs Dynamic)
- What version of Boost did you install? To what path? From where did you download it?
- What git hash of the C++ driver are you using?
- What CMake invocation did you use to generate the C++ driver build system?
- What CMake or msbuild invocation did you use to build the C++ driver?
- Which boost library (typically there are several in an install) did the C++ driver build select to link against? This may be affected by boost's autolink facility.
- When you run the test or example, and you get a crash, do you also get a stack trace? If so, can you provide the stack trace? If not, can you run the example under the VS debugger so you can get the stack?

Thanks,
Andrew


To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.

nathan lachenmyer

unread,
Oct 19, 2016, 12:00:13 PM10/19/16
to mongodb-user
No worries!  I understand completely :)

* I'm using Microsoft Visual Studio Community Edition 2015 Update 3
* I'm using the releases 1.3.4 of the C driver available here: https://github.com/mongodb/mongo-c-driver/releases/download/1.3.4/mongo-c-driver-1.3.4.tar.gz
* I used

cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver"

to build libbson, and then

cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver" "-DBSON_ROOT_DIR=C:\mongo-c-driver"

to build the C driver.

* I built it:

msbuild.exe ALL_BUILD.vcxproj
msbuild.exe INSTALL.vcxproj

* Built with whatever CRT the default was -- looks like Debug.

* Downloaded Boost 1.58 from sourceforge (https://sourceforge.net/projects/boost/files/boost/1.58.0/). I dumped it in C:\User\$user\Downloads.

* Using C++ Driver 3.0.02 from the releases page (https://github.com/mongodb/mongo-cxx-driver/releases)

* Used the following CMake invocation

cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver -DLIBBSON_DIR=C:\mongo-c-driver -DBoost_INCLUDE_DIR="C:\Users\me\Downloads\boost_1_58_0" -DLIBMONGOC_DIR=C:\mongo-c-driver -DCMAKE_BUILD_TYPE=Debug

* Built it with msbuild.exe:

msbuild.exe ALL_BUILD.vcxproj
msbuild.exe INSTALL.vcxproj

* I built directly against the downloaded 1_58 source, so it should have been 1.58 as far as I know.

* When I run the example, I get:

Debug Assertion Failed!

Program:
C:\Cinder\apps\mongo_test\vc2013\x64\Debug\mongo_test.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 980

Expression: __actr_first_block == header

The error seems to disappear if I comment out these lines:


for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}

The relevant part of the stack trace is:

mongo_test.exe!free_dbg_nolock(void * const block, const int block_use) Line 980
mongo_test.exe!_free_dbg(void * block, int block_use) Line 1011
[External Code]
mongo_test.exe!mongo_testApp::setup() Line 43

thanks!

Andrew Morrow

unread,
Oct 27, 2016, 6:17:09 PM10/27/16
to mongod...@googlegroups.com

Hi -

I've tried to reproduce your results, and, unfortunately, I cannot.

My next recommendation is that you try to follow, exactly, the Appveyor recipe that we use to test the driver. You can see each command exactly here:


Could you try running that process (adjusting paths to installation directories and the boost directory as needed), and see if that build passes the tests? If so, could you re-try with /p:Configuration=Debug? I also note that the C driver build never made use of this flag. I'm curious whether that is part of the issue.

Thanks,
Andrew


To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.

Andrew Morrow

unread,
Nov 1, 2016, 12:15:13 PM11/1/16
to mongod...@googlegroups.com

Hi -

Were you able to try following the process outlined in the appveyor.yml file? Are tests still failing for you?

Thanks,
Andrew

Reply all
Reply to author
Forward
0 new messages