Skip to content

Misuse of cmake link_directories to pass library filenames #12

@dmacks

Description

@dmacks

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions