0

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.

Community
  • 1
  • 1
Shinji Ikari
  • 173
  • 1
  • 12
  • You didn't mention listing specific libraries to link, only setting directories. Also, could you please share the exact errors you get? – xdg Nov 28 '16 at 17:17
  • See also https://stackoverflow.com/questions/40659559/cant-build-project-using-mongodb-c-driver-with-msvc – xdg Nov 28 '16 at 23:58
  • Looks like you haven't set a path to Boost: `Error C1083 Cannot open include file: 'boost/utility/string_ref.hpp': No such file or directory` – xdg Nov 29 '16 at 14:36
  • This [SO question](https://stackoverflow.com/questions/40485621/g-cannot-static-link-libmongcxxr3-0-2-but-dynamic-link-works) might also be helpful to look at. – xdg Dec 02 '16 at 18:29

3 Answers3

0

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.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Laza
  • 35
  • 1
  • 8
0

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>
xdg
  • 2,975
  • 19
  • 17
0

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)";
Shinji Ikari
  • 173
  • 1
  • 12