[CXX-2374] LNK2019: unresolved external symbol "__declspec(dllimport) using MongoDB in static mode Created: 19/Sep/21 Updated: 22/Jun/22 Resolved: 21/Sep/21 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Unknown |
| Reporter: | Dariusz D | Assignee: | Ezra Chung |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Hey
Ive build mongo C in static mode. 2x, 1x for debug, and 1x for debug-release. Between each build, I copied the generated files to a new folder as the debug files do not come with "d" suffix which then overwrites other files.
With these files, I then configures mongo CXX to use static mongo C files and asked it to produce both Static & Shared libraries.
That has been compiled. For this, I made 2 vs projects. 1 for debug and 1 for debug-release so to not confuse configs... I linked each project to their proper mongo C .lib files. So I end up with Mongo C & Mongo CXX in debug Mongo C & Mongo CXX in debug release. I've then included the resulting lib files in my cmake project using if statement to determine if I'm in debug or not >
After that when I try to run the app I get >
and 300 more errors like this.
This project was working with previous dynamic libraries, .dll, from last year. But as I was updating mongo I figures I might as well go with static & recompile it all. How can I "fix" this issue? Regards Dariusz
Win10x64 vs 17+ |
| Comments |
| Comment by Ezra Chung [ 21/Sep/21 ] | |||||||||
|
Thank you for reporting this question, dariusz1989@gmail.com. We recommend following the instructions to build the C++ driver as static libraries and refer to the static CMake project example given by the C++ driver for how to integrate the static libraries into your CMake project. To elaborate, rather than explicitly enumerating the static libraries in target_link_libraries(), we recommend using find_package(mongocxx) and the mongo::mongocxx_static target to link against the C++ driver as demonstrated in the static CMake project example. This will specify essential compile definitions such as MONGOCXX_STATIC (the absence of which is causing the __declspec(dllimport) errors) as well as handle the linking of all necessary dependencies. Additionally, rather than renaming the static libraries to avoid conflicts between build configurations, we recommend installing the libraries for each build configuration into a dedicated directory using CMAKE_INSTALL_PREFIX (or a multi-config generator) and conditionally provide the appropriate directory to CMAKE_PREFIX_PATH instead:
As this is neither a bug nor a feature request, we will close this issue. For further assistance, please create a post in our community forum. |