Library names crippled

I am trying to link a shared library on Windows using CMake. This shared library was compiled using Clang, and so I have to use GNU ld so that the debug symbols get propagated correctly (since Microsoft link.exe knows nothing about GNU style debug symbols). My shared library is dependent on import libraries for kernel32.dll and msvcrt.dll . I have a GNU style import library as part of a w32api installation.

However, when I specify the names of the import library in the target_link_libraries() call, the names become crippled, so target_link_libraries(${my_target} kernel32) becomes -lkernel32.lib on the command line. However, the name for the kernel32 import library is libkernel32.a , not libkernel32.lib.a , and as such the link does not work. I suspect this is because my copy of Clang uses Microsoft link.exe by default, and I set CMAKE_CXX_CREATE_SHARED_LIBRARY to override this behavior. If so, I will likely have to recompile Clang (and hope that I do not get the same behavior in a new copy).

EDIT: Klang is not to blame. I rebuilt Clang from scratch, only to find that the .lib suffix is ​​still bound automatically. Now I know that this is a CMake error. What am I doing wrong?

+4
source share
1 answer

You can try changing CMAKE_LINK_LIBRARY_SUFFIX :

 unset(CMAKE_LINK_LIBRARY_SUFFIX) target_link_libraries(${my_target} kernel32) 
+3
source

All Articles