Misuse of cmake link_directories to pass library filenames
dmacks opened this issue · 0 comments
Lots of CMakeLists.txt have things such as:
link_directories(${FOO_LIBRARIES})
either alone or accompanied by:
target_link_libraries(bar ${FOO_LIBRARIES})
or
target_link_libraries(bar foo)
The variable ${FOO_LIBRARIES}
contains the actual filename, not the path, so it should be passed directly via target_link_libraries()
. Paths passed via link_directories()
are supposed to be directories, and so they get passed as -L
flags, which is not correct when passing the actual filename. And if there is a ${FOO_LIBRARIES}
, that is what should be used rather than assuming that "foo" is the correct library name (overriding a user-specified alternative).
The typical symptom is a compile-time message such as:
ld: warning: -L path '/sw/lib/libusb.dylib' is not a directory
5d76e00 fixes a few of these cases, but there are still more.