Cmake Find_library

This is the reference page for cmake_find_package generator.Go to Integrations/CMake if you want to learn how to integrate your project or recipes with CMake.

Cmake Find_library Example

Command findpackage has two modes: Module mode and Config mode. You are trying to use Module mode when you actually need Config mode. Find.cmake file located within your project.

  1. Just to give you more insight on this and add details on top of Juan's answer, CMake will only able to find libraries with the.lib extension because it is what you are supposed to link against. And CMake explicitly defines that in the following file.
  2. Basic CMake, part 2: libraries By Martin Hořeňovský Jun 2nd 2018 Tags: CMake, Tutorial, C. My previous post about CMake provided a simple CMakeLists.txt for a small, self-contained, project. In practice, very few projects are fully self-contained, as they either depend on external libraries or are themselves libraries that other projects depend on.
  3. CMAKE linker does not find library; but library is found with findlibrary Hot Network Questions Cat stool sample collection in household with two cats.

The cmake_find_package generator creates a file for each requirement specified in the conanfile.

The name of the files follow the pattern Find<PKG-NAME>.cmake. So for the asio/1.14.0 package,a Findasio.cmake file will be generated.

Variables in Find<PKG-NAME>.cmake¶

Being <PKG-NAME> the package name used in the reference (by default) or the one declared in or incpp_info.names['cmake_find_package'] if specified:

Cmake Find_library Debug

<PKG-NAME>_VERSIONPackage version
<PKG-NAME>_INCLUDE_DIRSContaining all the include directories of the package
<PKG-NAME>_DEFINITIONSDefinitions of the library
<PKG-NAME>_LIBSLibrary paths to link
<PKG-NAME>_BUILD_MODULESList of CMake module files with functionalities for consumers
<PKG-NAME>_SYSTEM_LIBSSystem libraries to link
<PKG-NAME>_FRAMEWORKSFramework names to do a find_library()
<PKG-NAME>_FRAMEWORKS_FOUNDFound frameworks to link with after find_library()
<PKG-NAME>_FRAMEWORK_DIRSFramework directories to perform the find_library() of <PKG-NAME>_FRAMEWORKS

This file uses <PKG-NAME>_BUILD_MODULES values to include the files using the include(…) CMake directive after the targets arecreated. This makes functions or utilities exported by the package available for consumers just by setting find_package(<PKG-NAME>) in theCMakeLists.txt.

Moreover, this also adjusts CMAKE_MODULE_PATH and CMAKE_PREFIX_PATH to the values declared by the package in cpp_info.buildirs, somodules in those directories can be found.


Cmake Find_library Usage

Targets in Find<PKG-NAME>.cmake¶

A target named <PKG-NAME>::<PKG-NAME> target is generated with the following properties adjusted:

  • INTERFACE_INCLUDE_DIRECTORIES: Containing all the include directories of the package.
  • INTERFACE_LINK_LIBRARIES: Library paths to link.
  • INTERFACE_COMPILE_DEFINITIONS: Definitions of the library.

The targets are transitive. So, if your project depends on a packages A and B, and at the same timeA depends on C, the A target will contain automatically the properties of the C dependency, soin your CMakeLists.txt file you only need to find_package(A) and find_package(B).


If a recipe uses components, the targets generated will be <PKG-NAME>::<COMP-NAME> with the following properties adjusted:

  • INTERFACE_INCLUDE_DIRECTORIES: Containing all the include directories of the component.
  • INTERFACE_LINK_DIRECTORIES: Containing all the lib directories of the component.
  • INTERFACE_LINK_LIBRARIES: Containing the targets to link the component to (includes component’s libraries and dependencies).
  • INTERFACE_COMPILE_DEFINITIONS: Containing the definitions of the component.
  • INTERFACE_COMPILE_OPTIONS: Containing the compile options of the component.

Moreover, a global target <PKG-NAME>::<PKG-NAME> will be declared with the following properties adjusted:

  • INTERFACE_LINK_LIBRARIES: Containing all the component targets to link the global target to (includes package’s components only).



Name conflicts: If the name of the global target is the same for different packages, Conan will aggregate into this global targetall the components from all those different packages. This means that this global target will contain information coming from differentpackages. For the components themselves, a name conflict will result in one of them being inaccessible without further notice.