CMake find_library匹配行为?

Met*_*ome 11 cmake

一个指定find_library(名称PATHS path1..pathn)

我的问题是find_library如何匹配库文件的名称(在Windows和Linux上)?

例如,我无法让find_library在提供的GraphicsMagicK的Windows二进制安装中识别MagicK和MagicK ++ dll文件:

文件是:CORE_RL_magick_.dll

搜索查询:

magick CORE_RL_magick

不起作用.

Dom*_*kar 17

您可能需要查看此文档链接:

http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_library

http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable:CMAKE_FIND_LIBRARY_PREFIXES

http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable:CMAKE_FIND_LIBRARY_SUFFIXES

find_library可以接受一个或多个库名.这些名称前缀为CMAKE_FIND_LIBRARY_PREFIXES,并附加CMAKE_FIND_LIBRARY_SUFFIXES.应该为每个操作系统设置这两个变量,具体取决于图书馆的前缀或后缀.

在你的情况下,我会写Windows

SET(CMAKE_FIND_LIBRARY_PREFIXES "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
Run Code Online (Sandbox Code Playgroud)

对于Linux

SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
Run Code Online (Sandbox Code Playgroud)

然后写

find_library(
    magick
    CORE_RL_magick_ (or NAMES if there are multiple names for the same library on different systems)

    PATHS
      path1
      path2
    ...
    (other options that are specified in documentation and would be usefull to you)
)
Run Code Online (Sandbox Code Playgroud)

编辑:

CMAKE_FIND_LIBRARY_PREFIXES并且CMAKE_FIND_LIBRARY_SUFIXESproject()命令自动设置,因此首先调用它并find_library()在该点之后是比手动设置变量更好的解决方案.

  • 如果你想链接到它,你将需要 `.lib` 文件。在 Windows 上,它们被称为“导入库”,基本上告诉你的链接器你的 `.dll` 的导出符号。在执行期间,您将(仅)需要 `.dll` (2认同)