0

我尝试构建 Mongo C++11 驱动程序以在我的项目中使用。Mongo 驱动程序编译良好。使用它们的说明坚持认为,在将以下代码用于自己的项目时,以下代码也应该是.vcxproj我项目的一部分(如果使用 Visual Studio,我在 Windows 10 64 位上使用)。

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
    <IncludePath>c:\local\boost_1_59_0\;C:\mongo-cxx-driver\include\mongocxx\v_noabi;C:\mongo-cxx-driver\include\bsoncxx\v_noabi;C:\mongo-c-driver\include\libmongoc-1.0;C:\mongo-c-driver\include\libbson-1.0;$(IncludePath)</IncludePath>
    <LibraryPath>c:\mongo-c-driver\lib\;c:\mongo-cxx-driver\lib\;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>MONGOCXX_STATIC;BSONCXX_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies>libmongocxx.lib;libbsoncxx.lib;mongoc-static-1.0.lib;bson-1.0.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>

我需要什么样的代码来确保这段代码自动包含在我.vcxproj由 CMake 生成的代码中?我的 CMakeLists.txt 如下。

# CMakeLists.txt
# Building the test project
cmake_minimum_required(VERSION 3.7)

project(testing)

set(APP_SOURCES
    test.cpp
)

link_directories(../../installed_mongocxx/lib)
add_executable(testapp ${APP_SOURCES})
target_link_libraries(testapp mongocxx bsoncxx)

target_include_directories(testapp PUBLIC 
                            ../../installed_mongocxx/include/mongocxx/v_noabi
                            ../../installed_mongocxx/include/bsoncxx/v_noabi
                            E:/Software/Libraries/Boost/boost_1_64_0
)

install(TARGETS testapp 
        DESTINATION bin)
4

1 回答 1

1

使用 vcpkg 怎么样?它是一种编译库/驱动程序的简单方法。

按照 git 上的说明下载 vcpkg。https://github.com/Microsoft/vcpkg

步骤 1 C:\vcpkg>.\vcpkg 搜索 mongodb

你会看到类似的东西

mongo-c-driver 1.6.2-1 用 C 语言为 MongoDB 编写的客户端库。

mongo-cxx-driver 3.1.1-1 MongoDB C++ 驱动程序。

步骤 2 C:.\vcpkg 搜索 mongodb 安装 mongo-cxx-driver

然后拿杯咖啡....

步骤 3

C:\vcpkg>.\vcpkg 集成安装

完毕..

注意先决条件:

Windows 10、8.1 或 7

Visual Studio 2017 或 Visual Studio 2015 更新 3

然后只需创建一个项目并在项目中添加所需的包含。

由@JoyoWaseem 回答

如何使用 MongoDB 的 c++ 驱动程序构建程序?

于 2017-11-02T07:03:46.983 回答