I have a static library in /PATH directory, and when I tried to use the library with link_directories
as follows:
link_directories(/PATH)
target_lin
You call link_directories()
after creating executable: link_directories
affects only on targets, created after it: https://cmake.org/cmake/help/v3.4/command/link_directories.html. The result is that the correct -lHelloLib
flag is added to the target, but the lib search path isn't updated with a -L/PATH
flag.
Instead put the call to link_directories()
before you create any targets.
Since 3.3 version CMake documentation for target_link_libraries explicitely specifies, which kind of items for link it accepts. Among them:
So, you should specify either full path to the library file, or only name for the library, without file's extension(.a
) and prefix(lib
). Error message in you case shows, that CMake has tried to handle even filename-only library, but without success(some sort of Undefined Behaviour).
While previous versions of CMake doesn't document this command so clear, they, probably, follow same convention.