[CMake] Linking an entire static library

Petr Kmoch petr.kmoch at gmail.com
Mon Sep 10 03:29:07 EDT 2012


Hi all.

I'm on Windows, and I need a DLL composed of multiple static
libraries, any of which can define dllexport functions not otherwise
referenced in the DLL. The problem is that the Visual Studio linker
does not provide flags to link an entire static library (i.e. there is
no equivalent to ld's --whole-archive). I tried /OPT:NOREF, it didn't
help.

The only solution I can think of is to link all of the static
library's object files instead of the library itself (I verified
manually that this works). I cannot put source files into the DLL
directly, because the DLL is C and the static lib(s) are Fortran. My
question is thus: is there a way to retrieve the list of a target's
object files from cmake?

If there isn't any, I will resort to 'lib /list' and
pre-build/post-build magic, but I'd prefer a simpler solution. Or if
anyone happens to know a better way than linking all the object files,
please share it. However, .def files are not an option.

Thanks in advance.

Petr


More information about the CMake mailing list