VisualStudio CMake dynamic library: include/link all used functions in *single* dll

  c++, cmake, dll, visual-studio, visual-studio-2019

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.

too many dependencies expectd result

The main.dll file should include all the functions it imports, the compiler shouldn’t create separate dlls for each library.

I don’t know knob I need to turn, I can imagine several ways to edit:

  • The C++ Code of the Project (Classes, inlining functions ?)
  • The CMakeList.txt
  • The Arguments of MSVC (compiler, linker flags)
  • The Arguments of Ninja

Where should I start ?

Source: Windows Questions C++

LEAVE A COMMENT