[CMake] Why bother with FIND_LIBRARY()

Brad King brad.king at kitware.com
Wed Oct 27 16:20:47 EDT 2004


Eric Bolz wrote:
> I've been using FIND_LIBRARY do locate all of the libraries my project 
> needs.  I've noticed, however the libraries I find are not necessarily 
> the ones that get linked. For example, say I do the following:
> FIND_LIBRARY(LIB_1    NAMES  m         PATHS /usr/lib)
> FIND_LIBRARY(LIB_2    NAMES  socket  PATHS  /usr/local/lib)
> TARGET_LINK_LIBRARIES( my_executable   ${LIB_1}  ${LIB_2})
> In my Makefile, I get something like this:
> gcc   -L/usr/lib  -L/usr/local/lib -lm  -lsocket
> 
> The problem is that even though I did all the work of locating the 
> socket library in /usr/local/lib, I can't be sure that the linker won't 
> pick up a different one from /usr/lib
> cmake could do the following:
> gcc  -l/usr/lib/libm.a  -l/usr/local/lib/libsocket.a
> Why does cmake separate the library name from the path?
> This make me wonder about the value of FIND_LIBRARY().  Why bother with 
> FIND_LIBRARY if cmake is going to ignore what I found?  Is there some 
> benefit to FIND_LIBRARY() I'm not aware of?

CMake separates the -L and -l portions because some linkers will copy 
the entire static library in if a full path is given.  However, these 
tests were done with specyfing "/usr/lib/libfoo.a" instead of 
"-l/usr/lib/libfoo.a", so your solution may work.  It will have to be 
tested across many platforms, though.  Please submit this to the bug 
tracker:

http://www.cmake.org/Bug

Thanks,
-Brad


More information about the CMake mailing list