我尝试构建Mongo C ++ 11驱动程序以在我的项目中使用。 Mongo的驱动程序编译得很好。使用它们的说明坚持认为,当使用自己的项目时,下面的代码片段也应该是我项目的.vcxproj
的一部分(如果使用Visual Studio,我在Windows 10 64bit上执行)。
<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>
我需要使用哪种代码才能确保这段代码自动包含在CMake生成的.vcxproj
中?
我的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)
答案 0 :(得分:1)
如何使用vcpkg,这是编译库/驱动程序的简便方法。
按照git上提到的说明下载vcpkg。 https://github.com/Microsoft/vcpkg
步骤1 C:\ vcpkg&gt;。\ 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
然后拿一杯咖啡....Stap 3
C:\ vcpkg&gt;。\ vcpkg集成安装
完成..
注意先决条件:
Windows 10,8.1或7
Visual Studio 2017或Visual Studio 2015 Update 3
然后只需创建一个项目并在项目中添加所需的包含。
@JoyoWaseem回答