How to set up Visual Studio project settings with mongo-cxx-driver?

 ̄綄美尐妖づ 提交于 2019-12-06 14:50:59

问题


I have successfully build the version 3.0.3 of the MongoDB driver for C++ on Windows 10 with

CMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver

But I don't know how to set up a project in Visual Studio 2015 that can use this driver.
I found this post here, but I don't understand the exact solution. I tried the following properties but failed:

  • C/C++ > Additional Include Directories: C:\mongo-c-driver\include\libbson-1.0;C:\mongo-c-driver\include\libmongoc-1.0;C:\mongo-cxx-driver\include\bsoncxx\v_noabi;C:\mongo-cxx-driver\include\mongocxx\v_noabi;%(AdditionalIncludeDirectories)
  • Linker > Additional Library Directories: C:\mongo-cxx-driver\lib;%(AdditionalLibraryDirectories)

Visual Studio doesn't mark any errors, but when I try to compile the code, I get 401 errors.
I hope someone can help me.

EDIT: The complete list of all 401 errors is stored here.

EDIT: I startet a new project and used exactly the same settings. Now I just get 14 errors. The list of errors is stored here (EDIT: removed file).

EDIT: I added the following configuration:

  • Configuration Manager > Active Solution Platform: x64
  • C/C++ > Additional Include Directories: C:\Program Files\boost\boost_1_62_0;

Now I get the following errors.


回答1:


I'm also trying to build driver with VS2015 (Windows7). I made following changes to project:

# C/C++ | General | Additional Include Directories:C:\work\mongo-cxx\mongo-cxx-driver-r3.0.3\src\bsoncxx\include\libbson-1.0;C:\work\mongo-cxx\mongo-cxx-driver-r3.0.3\src\mongocxx\include\libmongoc-1.0;C:\work\mongo-cxx\mongo-cxx-driver-r3.0.3\src;C:\work\mongo-cxx\libbson-1.5.0\src\bson;C:\work\mongo-cxx\mongo-c-driver-1.5.0\src\mongoc;

# C/C++ | Preprocessor | Preprocessor Definitions:MONGOCXX_STATIC;BSONCXX_STATIC;**

# Librarian | General | Additional Dependencies:libbsoncxx.lib;mongoc-static-1.0.lib;

# Librarian | General | Additional Dependencies:C:\work\mongo-cxx\mongo-cxx-driver-r3.0.3\src\bsoncxx\$(Configuration);C:\work\mongo-cxx\mongo-c-driver-1.5.0\$(Configuration);

# Librarian | General | Link Library Dependencies: Yes

But when I tried to link static lib with test example I get linker error eg:

unresolved external symbol __imp_bson_append_array.

It seems there is something else which should be changed in project settings.




回答2:


Here's a sample .vcxproj, assuming components are in separate directories. You can compare it to what you have:

 <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:\libbson\lib;c:\mongo-c-driver\lib\;c:\mongo-cxx-driver\lib\;c:\libbson\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>



回答3:


First thank everyone for help! I got a workig solution with the following set up:

  • Configuration Manager > Active Solution Platform: x64
  • C/C++ > Additional Include Directories: C:\mongo-c-driver\include\libbson-1.0;C:\mongo-c-driver\include\libmongoc-1.0;C:\mongo-cxx-driver\include\bsoncxx\v_noabi;C:\mongo-cxx-driver\include\mongocxx\v_noabi;C:\Program Files\boost\boost_1_62_0;
  • Linker > Additional Library Directories: C:\mongo-cxx-driver\lib;
  • Linker > Input > Additional Dependencies: bsoncxx.lib;mongocxx.lib;
  • Build Events > Post-Build Event: COPY "C:\mongo-cxx-driver\bin\bsoncxx.dll" "$(OutDir)";COPY "C:\mongo-cxx-driver\bin\mongocxx.dll" "$(OutDir)";COPY "C:\mongo-c-driver\bin\libmongoc-1.0.dll" "$(OutDir)";COPY "C:\mongo-c-driver\bin\libbson-1.0.dll" "$(OutDir)";


来源:https://stackoverflow.com/questions/40828845/how-to-set-up-visual-studio-project-settings-with-mongo-cxx-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!