Mongo-cxx-driver库构建,但存在持久链接和调试问题

mongo-cxx-driver library builds but persistent linking and debug issues

本文关键字:链接 调试 问题 存在 构建 Mongo-cxx-driver      更新时间:2023-10-16

我试图在Windows 10和Visual Studio 2015上构建与Cinder一起使用的mongo-cxx-driver。Cinder使用的是Boost 1.58,所以我根据他们包含的Boost版本构建了驱动程序。

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

这是我所做的,反映了这里的官方说明

步骤1

我按照这里的说明安装MongoDB C驱动程序。简单地复制/粘贴CMake调用在Windows构建指令下工作完美。

步骤2

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

步骤3

我卸载了我从github下载的mongo-cxx-driver-3.0.2;然后我进入mongo-cxx-driver-r3.0.2mongo-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:Cinderinclude -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_testsrcmongo_testApp.cpp 39  

我怀疑也许问题是我如何链接Boost/std::experimental,但我已经尝试了几个不同的变化(禁用使用Boost和使用std::experimental的polyfill代替),但这似乎并没有创建一个工作库。或者可能与调试/发布或x64与x86不匹配?

谁能指出这个构建过程中的错误?

谢谢!

[EDIT]在mongo-cxx-driver中运行包含的测试,包括用于调试目的的输出:

~Downloadsmongo-cxx-driver-r3.0.2mongo-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 "~Downloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj" on node 1 (default targets).
Project "~Downloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj" (1) is building "~Downloadsmongo-cxx-dr
iver-r3.0.2mongo-cxx-driver-r3.0.2ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
InitializeBuildStatus:
  Creating "x64DebugZERO_CHECKZERO_CHECK.tlogunsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
  All outputs are up-to-date.
FinalizeBuildStatus:
  Deleting file "x64DebugZERO_CHECKZERO_CHECK.tlogunsuccessfulbuild".
  Touching "x64DebugZERO_CHECKZERO_CHECK.tlogZERO_CHECK.lastbuildstate".
Done Building Project "~Downloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2ZERO_CHECK.vcxproj" (default targets).
PrepareForBuild:
  Creating directory "x64DebugRUN_TESTS".
  Creating directory "x64DebugRUN_TESTSRUN_TESTS.tlog".
InitializeBuildStatus:
  Creating "x64DebugRUN_TESTSRUN_TESTS.tlogunsuccessfulbuild" because "AlwaysCreate" was specified.
PostBuildEvent:
  setlocal
  "C:Program FilesCMakebinctest.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)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: The command "setlocalr [~Downloadsmongo-cxx-d
river-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: "C:Program FilesCMakebinctest.exe" --force-new-ctest-process -C Debug
r [~Downloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :cmEndr [~Downloads
mongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: :cmEndr [~Downloadsmongo-cxx-driver-r3.0.2mo
ngo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDoner [C:Usersnat
han lachenmyerDownloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: :cmErrorLevelr [~Downloadsmongo-cxx-driver-r3
.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: exit /b %1r [~Downloadsmongo-cxx-driver-r3.0.
2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: :cmDoner [~Downloadsmongo-cxx-driver-r3.0.2m
ongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :VCEndr [~Downloads
mongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: :VCEnd" exited with code 8. [~Downloadsmongo-c
xx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
Done Building Project "~Downloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj" (default targets) -- FAILED.

Build FAILED.
"~Downloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj" (default target) (1) ->
(PostBuildEvent target) ->
  C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: The command "setlocalr [~Downloadsmongo-cxx
-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: "C:Program FilesCMakebinctest.exe" --force-new-ctest-process -C Debug
r [~Downloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :cmEndr [~Downloads
mongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: :cmEndr [~Downloadsmongo-cxx-driver-r3.0.2mo
ngo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDoner [C:Usersnat
han lachenmyerDownloadsmongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: :cmErrorLevelr [~Downloadsmongo-cxx-driver-r3
.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: exit /b %1r [~Downloadsmongo-cxx-driver-r3.0.
2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: :cmDoner [~Downloadsmongo-cxx-driver-r3.0.2m
ongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :VCEndr [~Downloads
mongo-cxx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.CppCommon.targets(133,5): error MSB3073: :VCEnd" exited with code 8. [~Downloadsmongo-c
xx-driver-r3.0.2mongo-cxx-driver-r3.0.2RUN_TESTS.vcxproj]
    0 Warning(s)
    1 Error(s)
Time Elapsed 00:00:00.71

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