Hi,
Using arch linux with MinGW and cmake 3.19. The following code works on Windows / MSVC / cmake version 3.18.20081302-MSVC_2, but on MinGW does not find any dependencies at all. mylib
is a shared library. On Windows CMake seems to use dumpbin
, on MinGW it uses objdump
.
install(CODE [[
message(STATUS "Looking for deps in ${CMAKE_SYSTEM_LIBRARY_PATH};${CMAKE_MINGW_SYSTEM_LIBRARY_PATH}")
file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR deps_resolved
UNRESOLVED_DEPENDENCIES_VAR deps_unresolved
LIBRARIES $<TARGET_FILE:mylib>
DIRECTORIES ${CMAKE_SYSTEM_LIBRARY_PATH} ${CMAKE_MINGW_SYSTEM_LIBRARY_PATH}
PRE_EXCLUDE_REGEXES "api-ms-*" "ext-ms-*"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
)
message(STATUS "Resolving runtime dependencies for $<TARGET_FILE:mylib>")
foreach(dep ${deps_resolved})
file(INSTALL ${dep} DESTINATION ${CMAKE_INSTALL_PREFIX})
endforeach()
foreach(dep ${deps_unresolved})
message(WARNING "Runtime dependency ${dep} could not be resolved.")
endforeach()
]])
The variable CMAKE_MINGW_SYSTEM_LIBRARY_PATH
is defined using install(CODE "set(CMAKE_MINGW_SYSTEM_LIBRARY_PATH \"${CMAKE_FIND_ROOT_PATH}/bin/\")")
and points to the correct path on my system which is /usr/x86_64-w64-mingw32/bin
.
if I manually do objdump
i do get back some deps (although not recursive so not complete):
$ objdump -x mylib.dll | grep DLL
DLL
vma: Hint Time Forward DLL First
DLL Name: libgcc_s_seh-1.dll
DLL Name: KERNEL32.dll
DLL Name: msvcrt.dll
DLL Name: libstdc++-6.dll
DLL Name: libopenlibm.dll
DLL Name: libceres.dll
DLL Name: libglog.dll
So in short, works on Windows 10, doesn’t work on Arch/MinGW. Any ideas what might be going on here? Thanks.