【问题标题】:mongo-cxx-driver library builds but persistent linking and debug issuesmongo-cxx-driver 库构建但持久的链接和调试问题
【发布时间】:2016-10-11 16:38:00
【问题描述】:

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

我尝试完全按照 github 上描述的说明进行操作,但我得到的最终库和 dll 似乎存在问题。我希望有人帮助我调试我的编译出错的地方!

这就是我所做的,镜像官方说明here

步骤 1

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

第二步

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

第三步

我解压了从 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 breakpoint,断点位于bsoncxx.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

【问题讨论】:

  • 你能试试 3.0.2 驱动和 Boost 1.59 吗?我们已经收到了使用这种组合在 MSVC 上取得成功的报告。
  • 在使用 3.0.1 驱动程序和 Boost 1.58 时,MSVC 是否存在已知问题?
  • 没有已知问题,但我们也没有专门测试过这种组合。
  • 尝试 v3.0.2 驱动程序解决了基本的构建器问题——我没有遇到未链接对象的问题。但我仍然在调试模式下崩溃,在发布模式下出现断点。
  • 我尝试运行测试,但构建失败了所有 3 个测试。我根据 README 使用 1.3.4 版本重建了 mongo-c-driver,但仍然失败。

标签: c++ mongodb boost visual-studio-2015 mongo-cxx-driver


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多