[cmake-developers] [PATCH] New module FindLibDl
Chuck Atkins
chuck.atkins at kitware.com
Fri Nov 21 14:59:38 EST 2014
Hi Roger,
> However, do I still need to independently check for <dlfcn.h>?
How do I know that I have a working dlopen?
dlopen defined in dlfcn.h is part of POSIX so generally if you're on a *nix
system then you can rely on it being there. The associated library,
however, is a different story, hence CMAKE_DL_LIBS. So then your code
would be:
----- Begin fooUnix.c -----
...
#include <dlfcn.h>
...
void foo()
{
void *dl = dlopen(...);
...
}
...
----- End fooUnix.c -----
----- Begin CMakeLists.txt -----
...
if(UNIX)
add_library(FooLib fooUnix.c)
if(CMAKE_DL_LIBS)
target_link_libraries(FooLib ${CMAKE_DL_LIBS})
endif()
endif()
...
----- End CMakeLists.txt -----
which is actually overkill since you could avoid the if(CMAKE_DL_LIBS)
check entirely since passing an empty library list to target_link_libraries
is still valid.
- Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20141121/10eaf472/attachment-0001.html>
More information about the cmake-developers
mailing list