When you create a DLL in CMake on windows you need you to link dependencies by adding the *.lib
file to the target link libraries. For instance, if we have a DLL target called dll_target
add_library(dll_target SHARED ${sources})
That depends on target depA
, as I understand it, standard practice would be to link against depA.lib
.
target_link_libraries(dll_target PRIVATE :C:/full/path/to/depA/install/lib/depA.lib")
This shouldn't be confused with depA.lib
the static library, but the depA.lib
associated with depA.dll
which is built when you build depA.dll
. The latter is needed at runtime.
On Linux, I have been able to build all of my dependencies as .a
files and then use these static libraries to construct a shared library (.so
). However, when I try the same with windows, I get a slew of linker errors (mostly LNK2019
but the occasional LNK2001
).
I've been searching for this answer for days now: How can I use static libraries on windows to construct a self-contained DLL, so that it has no external dependencies?