I have a VisualStudio-2019 C++ Project which uses CMake and Ninja to build a dll, the Project uses functions from a few Libraries like protobuf
and spdlog
, which I have installed using vcpkg
.
When building, the output gets written to four distinct dll files and all of them are needed for the main-dll
to run.
Below are two screenshots: left the current state and right the expected state.
The main.dll
file should include all the functions it imports, the compiler shouldn't create separate dlls for each library.
I don't which know knob I need to turn, I can imagine several ways to edit:
Where should I start ?
Setting the mentioned flags or appending -static
to the import library components had no effect, I went as far as
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_MODULE_LINKER_FLAGS "-static")
set(CMAKE_SHARED_LINKER_FLAGS "-static")
set(CMAKE_STATIC_LINKER_FLAGS "-static")
But this didn't help a bit.
As it turned out this is a problem with vcpkg
:
I had installed the packages with the triplet x64-windows
, which builds for dynamic linkage, installing the packages with
vcpkg install --triplet=x64-windows-static protobuf spdlog
makes static linking possible. If the static variants are not installed, the build proceeds silently with the dynamic ones.