CMake 找不到包含/库 [英] CMake does not find includes / libraries

查看:106
本文介绍了CMake 找不到包含/库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用 CMake 的项目中使用一些第三方头文件(或库).但它没有找到标题(库).为什么 CMake 找不到?

I want to use some third-party headers (or a library) in a project that uses CMake. But it does not find the headers (the library). Why does CMake not find it?

推荐答案

CMake 的 find 例程在某些特定位置查找标头和库.这包括 PATH 变量,以及已安装软件的默认位置,例如,对于许多 Linuces /usr/bin.此外,它还会评估 CMake 变量 CMAKE_PREFIX_PATH.

CMake's find routines look for headers and libraries at some specific places. This includes the PATH variable, and the default locations for installed software, e.g., for many Linuces /usr/bin. Additionally, it evaluates the CMake variable CMAKE_PREFIX_PATH.

您有两种方法可以帮助 CMake 找到所需的文件:

You have two possibilities to help CMake finding the required files:

  1. 检查您的软件是否安装正确.对于自编译软件,通常通过make install 或类似方法完成.如果您使用包(RPM 或 deb),它们通常已安装并且可以通过 PATH 变量找到.

  1. Check whether your software is properly installed. For self-compiled software, that's usually done by make install or similar. If you use packages (RPM or deb), they are in general installed and can be found with the PATH variable.

如果您不想或无法安装该软件,请将其路径添加到 CMAKE_PREFIX_PATH 变量中.将其传递给 CMake 调用 cmake -DCMAKE_PREFIX_PATH=/path/to/software .. 或在 CMake-GUI 中编辑/添加相应字段.

If you don't want or can install the software, add its path to the CMAKE_PREFIX_PATH variable. Either pass it to the CMake call cmake -DCMAKE_PREFIX_PATH=/path/to/software .. or edit/add the according field in the CMake-GUI.

必须删除CMakeCache.txt,否则CMake将找不到库,因为它不检查而是使用缓存的结果.重新运行 CMake,它应该可以工作了.

You have to delete the CMakeCache.txt, otherwise CMake will not find the library, because it does not check but use the cached result. Re-run CMake and it should work.

如果您的系统上有多个版本的库,请将您想要使用的版本添加到 CMAKE_PREFIX_PATH,因为变量会在系统路径变量之前进行评估.

If you have multiple versions of a library on your system, add the one you want to use to the CMAKE_PREFIX_PATH as the variables gets evaluated prior to the system path variables.

某些模块提供了诸如 mylib_DIRmylib_ROOT 之类的特定变量来指示搜索路径.不鼓励使用它,它们只是为了向后兼容.新模块没有这些模块,添加这些变量的提交被 CMake 开发人员拒绝.

Some modules offer specific variables like mylib_DIR or mylib_ROOT to indicate the search path. Its use is discouraged and they are only left for backwards-compatibility. New modules don't have these modules and commits adding such variables are rejected by the CMake developers.

有关 CMake 如何搜索文件以及搜索顺序的更多详细信息,请参见文档:https://cmake.org/cmake/help/latest/command/find_library.html

More details on how CMake searches files and in which order can be found in the documentation: https://cmake.org/cmake/help/latest/command/find_library.html

这篇关于CMake 找不到包含/库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆