Windows-GNU: set CMAKE_DL_LIBS to "dl" on MINGW
Merge request reports
Activity
assigned to @brad.king
added workflow:nightly-testing label
Well but assuming you are compiling a package which uses dlopen & co. on MinGW, you will need dlfcn (aka https://github.com/dlfcn-win32/dlfcn-win32) in any case.
Correct, but
CMAKE_DL_LIBS
is used in a lot of CMake packages in a pattern that if it's not empty, append it to the set of libraries. However, for exampleFindLua
does precisely that and Lua does not depend onlibdl
on Windows.I'm not saying you're wrong in that
CMAKE_DL_LIBS
should be set to this value (after all that's what matches the description of the variable), but if we do that, we at least need to change the modulesFindLua
,FindQt3
,Qt4ConfigDependentSettings
,FindCUDA
andFindLTTngUST
to reflect this change for MinGW.Oops, forget about LTTngUST, that's a Linux-specific library.
In FindCUDA, there's one reference to
CMAKE_DL_LIBS
here.cudart
won't be needinglibdl
on Windows - but CUDA cannot be used with GNU compilers on Windows either, so I suppose it's fine to just ignore that one.I had just grepped quickly for which of our modules consume
CMAKE_DL_LIBS
. I think however that cmcurl's CMakeList also requires an adaption.No, the contrary, as long as they're guarded by
if(UNIX)
logic, it's fine. These libraries after all support using native Windows mechanism instead ofdlopen
and therefore don't needlibdl
. From what I can see, the Qt4 and cmcurl occurrences are problematic because they lack such checks.That's true, but
CMAKE_DL_LIBS
is currently being described as "Name of library containing dlopen and dlclose." Whatlibzip
does is to usedlfcn.h
on MinGW while relying onCMAKE_DL_LIBS
for the linking aspect. Given the current documentation, I'd argue that's a valid interpretation of the behavior.I don't think there's much of a problem setting
CMAKE_DL_LIBS
todl
for MinGW, but we need to ensure that all occurrences in CMake guard it withif(UNIX)
then, iflibdl
is not needed for the library in question on Windows / MinGW.added workflow:wip and removed workflow:nightly-testing labels
- Resolved by Ben Boeckel
Unfortunately this behavior change can break existing projects in cases similar to what @ChrisTX pointed out. For example, CMake's own build breaks with this. See the error here. I tracked it down to this change, which causes a difference. Prior to the change, curl would configure as:
-- Looking for getch in ws2_32; -- Looking for getch in ws2_32; - found -- Looking for getch in winmm;ws2_32 -- Looking for getch in winmm;ws2_32 - found
With this change:
-- Looking for getch in ws2_32;dl -- Looking for getch in ws2_32;dl - not found -- Looking for getch in winmm;dl -- Looking for getch in winmm;dl - not found
added 1 commit
- d43baf8b - cmcurl: avoid usage of CMAKE_DL_LIBS on MinGW
My analyses:
-
FindQt4ConfigDependentSettings
: guarded byQ_WS_X11
already -
FindQt3
: guarded byif (UNIX)
-
FindLua
: guarded byif (UNIX)
-
FindCuda
: relying on the non-support of mingw by CUDA -
FindLTTngUST
: this is a find module for a Linux tracing framework; leaving as-is since it probably unconditionally usesdlopen
-
cmcurl
: updated to avoid its usage on non-UNIX
-
removed workflow:wip label