Generating import libraries without .dll, only through .def
I am trying to generate an import library for an external DLL that does not have one.
This means that I do not have the sources but only the .def
file.
Is there a way to create an import library only in CMake ?
The linker command only needs to use /DEF:
without any other inputs to work:
lib /DEF:somelib.def /Out:somelib.lib /machine:x86
I tried a few things but none seems to work:
-
SHARED
with no source file other than the.def
will not invoke the linker, and thus not generate any.lib
nor.dll
-
SHARED
with an empty.cpp
source file will try to generate both.lib
and.dll
, which fails since symbols referenced by the.def
do not exist -
STATIC
with no source file other than the.def
will not invoke the linker, and thus not generate any.lib
-
STATIC
with an empty.cpp
source file will not invoke the linker, and thus not generate a.lib
but the.def
will not be used
I also tried setting STATIC_LIBRARY_OPTIONS
(see below), but if you provide .obj
files to the linker, it will not work as it will try to find functions referenced in the .def as if we were generating a .dll
. And since the linker is not invoked without any .cpp
file in the source list, well, I'm stuck.
set_target_properties(Fog PROPERTIES
LINKER_LANGUAGE CXX
STATIC_LIBRARY_OPTIONS "/DEF:${CMAKE_CURRENT_LIST_DIR}/definitions/Fog.${D2MOO_ORDINALS_VERSION}.def"
)
Is using a custom target + and IMPORTED
cmake library the only thing I can use for this ?
Am I missing something ? I know it's pretty unusual to create an import library without also creating a .dll, is that something CMake should support out of the box ?