CMake find_library matching behavior?

2019-01-18 13:23发布

One specifies find_library( name PATHS path1..pathn)

My question is how does find_library match name to the library file (on Windows and Linux)?

For example, I am unable to have find_library identify the MagicK and MagicK++ dll files in the provided windows binary installation of GraphicsMagicK:

The files is: CORE_RL_magick_.dll

Searching for the queries:

magick CORE_RL_magick

does not work.

标签: cmake
2条回答
祖国的老花朵
2楼-- · 2019-01-18 13:51

You might want to take a look at this documentation links:

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 may accept one or more library names. Those names get the value of CMAKE_FIND_LIBRARY_PREFIXES prepended and CMAKE_FIND_LIBRARY_SUFFIXES appended. This two variables should be set for each OS depending on how the librares are prefixed or suffixed there.

In your case I'd write for Windows

SET(CMAKE_FIND_LIBRARY_PREFIXES "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")

and for Linux

SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")

and then write

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)
)

EDIT:

CMAKE_FIND_LIBRARY_PREFIXES and CMAKE_FIND_LIBRARY_SUFIXES are set automatically by project() command so calling it first and find_library() after that point is a better solution than setting the variables manually.

查看更多
Lonely孤独者°
3楼-- · 2019-01-18 13:51

Why not use find_file() instead of find_library() if you want to find a .dll.

查看更多
登录 后发表回答