2

我正在尝试构建 mongo-cxx-driver 以在带有 Visual Studio 2015 的 Windows 10 上与 Cinder 一起使用。Cinder 使用 Boost 1.58,因此我针对他们包含的 Boost 版本构建了驱动程序。

我尝试完全按照 github 上的说明进行操作,但是我得到的最终库和 dll 似乎与它们有问题。我很想帮助调试我的编译出错的地方!

这就是我所做的,在此处镜像官方说明

步骤1

我按照此处的说明安装了 MongoDB C 驱动程序。只需在 Windows 构建说明下复制/粘贴 CMake 调用即可完美运行。

第2步

由于我使用的是 Windows 和 Visual Studio 2015,因此我应该为 Polyfill 使用 Boost 选项。

第 3 步

我解压了从 github 下载的 mongo-cxx-driver-3.0.2;然后我进入mongo-cxx-driver-r3.0.2\mongo-cxx-driver-r3.0.2并运行 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 ..

然后构建并安装项目:

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

一切运行良好,我从 CMake 确认没有错误。万岁!

问题

在测试时,我尝试运行测试程序

#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");
}

如果我在 Debug 中运行它,那么它会在打印出带有“Debug Assertion Failed”消息的数据库后崩溃:

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

检查断点表明它会导致文件末尾的行出现错误——可能是在从行清理期间

std::cout << bsoncxx::to_json(doc) << std::endl

我的第一个怀疑是 .lib 文件和 .dll 可能是为发布而构建的——所以我在发布时构建了它。

mongo_test.exe has triggered a breakpointbsoncxx.dll!bsoncxx::v_noabi::string::view_or_value::terminated().

在尝试调试时,我将插入行更改为:

mongocxx::result::insert_one result = collection.insert_one(document.view());

为了收集更多的调试信息。我惊讶地发现编译时不会出现 C2440 错误:

'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  

我怀疑问题可能出在我如何链接 Boost / std::experimental 上,但我尝试了几种不同的变体(禁用使用 boost 并使用 std::experimental 代替 polyfill),但这并没有似乎创建了一个工作库。或者可能与 Debug / Release 或 x64 与 x86 不匹配?

任何人都可以识别此构建过程中的失误吗?

谢谢!

[编辑] 运行 mongo-cxx-driver 中包含的测试,包括此处用于调试目的的输出:

~\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
4

1 回答 1

0

我知道这是一个老问题,但我今天遇到了这个问题,所以我会在这里将我的解决方案发布给任何可能感兴趣的人。它仅在调试模式下发生,当我将 /MD 更改为 /MDd 时错误停止。您可能必须重新编译 mongocxx 以匹配您的设置。

于 2022-01-29T15:07:07.700 回答