[CXX-1789] Issues using C++ driver in Visual Studio projects Created: 14/Jun/19 Updated: 27/Oct/23 Resolved: 26/Sep/23 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | Documentation |
| Affects Version/s: | 3.3.1, 3.4.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Mason Hieb | Assignee: | Adrian Dole |
| Resolution: | Gone away | Votes: | 1 |
| Labels: | rp-track, size-medium | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 10 64 bit |
||
| Issue Links: |
|
||||||||||||
| Epic Link: | CXX-2634 | ||||||||||||
| Quarter: | FY24Q3 | ||||||||||||
| 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'"> |
| Comments |
| Comment by Adrian Dole [ 26/Sep/23 ] | |||||||||||||||||||||
|
Cannot reproduce as of:
Example program successfully builds from Visual Studio using shared libraries. | |||||||||||||||||||||
| Comment by Adrian Dole [ 26/Sep/23 ] | |||||||||||||||||||||
|
Cannot reproduce as of:
Example program successfully builds from Visual Studio using shared libraries. | |||||||||||||||||||||
| Comment by Mason Hieb [ 22/Apr/20 ] | |||||||||||||||||||||
|
Yeah its been a while but it is likely an issue when building the test program through the IDE | |||||||||||||||||||||
| Comment by Kevin Albertson [ 27/Mar/20 ] | |||||||||||||||||||||
|
Hi mason and ilkash2@gmail.com, Apologies for the delayed response. To clarify, the test you are referring to is the reference to test.cpp in Step 6 of the installation instructions, correct? In case it is helpful, I am able to build it on Windows with cmake. I installed the C driver with the following:
And the C++ driver with the following:
Then, created a CMakeLists.txt for test.cpp:
And compiled it with the following:
So I assume this is only an issue when building through the IDE itself with the manually modified .vcxproj file? The documentation for building precedes the current team working on the C++ driver, and I do agree it needs improved. | |||||||||||||||||||||
| Comment by Mason Hieb [ 16/Mar/20 ] | |||||||||||||||||||||
|
1. The documentation explaining that you need to use those dependencies exists, but its the documentation for libmongoc: http://mongoc.org/libmongoc/current/visual-studio-guide.html (I didn't find that libmongoc guide until I had already figured out the dependencies from some stackexchange threads, so perhaps there might be a better way to present the information in the official MongoDB guide)
2. It looks like it's status has been updated just now from "Open" to "Needs Triage" | |||||||||||||||||||||
| Comment by Ilya Denisov [ 16/Mar/20 ] | |||||||||||||||||||||
|
@Mason Hieb: yes, it helps, thank you so much! I will try to add this driver to my project. However, here are some questions:
| |||||||||||||||||||||
| Comment by Mason Hieb [ 10/Mar/20 ] | |||||||||||||||||||||
|
Ilya: did you see my comment? Does your project require MongoDB to be dynamically linked? | |||||||||||||||||||||
| Comment by Ilya Denisov [ 10/Mar/20 ] | |||||||||||||||||||||
|
I experience the same issue in VS2019. I've tried at least 3 versions of boost (started with 1.56.0, as it is described in the documentation and during the CMake build. Then I tried with 1.59 as it solves one issue and then 1.60 as it solves another one). Then I stuck with 2 errors in 3.4.0 that were solved in 3.4.1. And now I'm stuck here with one unresolved external symbol. And this issue was not assigned to anyone for 8 months, so probably it would be solved somewhere in 2021 | |||||||||||||||||||||
| Comment by Mason Hieb [ 09/Sep/19 ] | |||||||||||||||||||||
|
Here is the solution I found and am using: I don't know if it solves the problem in terms of dynamic linking but I built the cxx connector with static libraries (using -DBUILD_SHARED_LIBS=OFF) and then placed all of these in my additional dependencies: mongocxx-static.lib bsoncxx-static.lib mongoc-static-1.0.lib bson-static-1.0.lib ws2_32.lib Secur32.lib Crypt32.lib BCrypt.lib Dnsapi.lib And now I can build and run the test program without issue. |