CMake's link_directories issue with static library (on Mac OS X)

后端 未结 1 1775
时光说笑
时光说笑 2021-01-26 03:04

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         


        
1条回答
  •  梦毁少年i
    2021-01-26 03:54

    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:

    • A full path to a library file
    • A plain library name

    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.

    0 讨论(0)
提交回复
热议问题