cmake prevents linking static runtime with absolute path to a static lib
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
When an absolute path to a static lib i.e. ${ZLIB_LIBRARIES}
, which expands to D:/msys64/mingw64/lib/libz.a
is added to target_link_libraries, the library is linked using its name (-lz
), preprended with -Wl,-Bstatic
and appended with -Wl,-Bdynamic
. Because the libraries appear after any link flags, the latter one cancels out any flags to link statically (-static -static-libstdc++ -static-libgcc
) and the final executable links against the dynamic runtime.
Using an imported target i.e. ZLIB::ZLIB
, the library is added using its absolute path without any additional flags.
Edited by Brad King