Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-1789

Issues using C++ driver in Visual Studio projects

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 3.3.1, 3.4.0
    • Fix Version/s: None
    • Component/s: Documentation
    • Labels:
    • Environment:
      Windows 10 64 bit
    • Backwards Compatibility:
      Fully Compatible

      Description

      For the past two days I have tried to build and test mongocxx on two different Windows 10 machines, one using VS2015 and the other using VS2017. The builds install without errors (though had initial issues with ENABLE_EXTRA_ALIGNMENT). However, once I try to build the exact test code from the MongoDB installation guide (http://mongocxx.org/mongocxx-v3/installation/), I get the following linker error:

       

      error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const mongocxx::v_noabi::uri::k_default_uri" (?k_default_uri@uri@v_noabi@mongocxx@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)

       

      I have rebuilt with boost 1.59, boost 1.68, boost 1.70, and using C++17 with no boost.

      I have tested from builds with mongocxx 3.4.0 with mongoc 1.14.0, and mongocxx 3.3.1 with mongoc 1.10.1, and this is always the error I end up at.

      I know Visual Studio sees mongocxx.lib, because if I remove it I get a ton of linker errors instead of just one.

      The one and ONLY way I got the test program to run was to build mongocxx with static libraries, and in the test program link them along with the shared libraries for the mongo c driver. However, that doesn't seem like the right solution because as the installation guide says:

      "Linking an application against both shared libmongoc and static mongocxx is not supported, nor is linking against both static libmongoc and shared mongocxx."

       

      What is also annoying is that if I open up mongocxx.lib and search for "?k_default_uri@uri..." I find it. So its in there. But something is wrong apparently.

      Note that if I comment out everything below the first line in the main function (everything below "mongocxx::instance inst{};"), then it compiles fine, so its specifically this part that it is unable to resolve: "mongocxx::uri{}"

       

      Is something being built as 32 bit that I don't realize? Or something being built in release mode that I don't realize? My mongocxx and mongo c builds all say Debug/64 bit, but maybe there is something I'm not seeing

       

      Here are my cmake commands for the c driver and cxx driver respectively:

      cmake -G "Visual Studio 15 2017 Win64" "-DCMAKE_BUILD_TYPE=Debug" "-DENABLE_EXTRA_ALIGNMENT=OFF" "-DCMAKE_INSTALL_PREFIX=C:\<path removed>\mongo-c-driver" "-DCMAKE_PREFIX_PATH=C:\<path removed>\mongo-c-driver" ..

      cmake -G "Visual Studio 15 2017 Win64" "-DCMAKE_BUILD_TYPE=Debug" "-DBSONCXX_POLY_USE_BOOST=1" "-DCMAKE_INSTALL_PREFIX=C:\<path removed>\mongo-cxx-driver" "-DCMAKE_PREFIX_PATH=C:\<path removed>\mongo-c-driver" "-DBOOST_ROOT=C:\<path removed>\boost_1_68_0" ..

      And after each of these I run the following:

      msbuild.exe /p:Configuration=Debug ALL_BUILD.vcxproj

      msbuild.exe /p:Configuration=Debug INSTALL.vcxproj

       

      And these are the relevant properties from my VS project:

      <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
      <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <ConformanceMode>true</ConformanceMode>
      <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\libraries\boost_1_68_0;$(ProjectDir)..\..\..\libraries\mongo-cxx-driver\include\mongocxx\v_noabi;$(ProjectDir)..\..\..\libraries\mongo-c-driver\include\include\libmongoc-1.0;$(ProjectDir)..\..\..\libraries\mongo-c-driver\include\libbson-1.0;$(ProjectDir)..\..\..\libraries\mongo-cxx-driver\include\bsoncxx\v_noabi</AdditionalIncludeDirectories>
      <PreprocessorDefinitions>MONGOCXX_STATIC;BSONCXX_STATIC;MONGOC_STATIC;DBSON_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      </ClCompile>
      <Link>
      <AdditionalLibraryDirectories>$(ProjectDir)..\..\..\libraries\boost_1_68_0\stage\lib;$(ProjectDir)..\..\..\libraries\mongo-c-driver\lib;$(ProjectDir)..\..\..\libraries\mongo-cxx-driver\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <AdditionalDependencies>mongocxx.lib;bsoncxx.lib;mongoc-static-1.0.lib;bson-1.0.lib;%(AdditionalDependencies)</AdditionalDependencies>
      </Link>
      </ItemDefinitionGroup>

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              mason Mason Hieb
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated: