CMake找不到includes / libraries [英] CMake does not find includes / libraries
问题描述
我想在使用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的查找例程在某些特定位置寻找头文件和库。这包括 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找到所需的文件: / p>
You have two possibilities to help CMake finding the required files:
-
检查您的软件是否已正确安装。对于自编译的软件,这通常由
make install
或类似的做。如果使用软件包(RPM或deb),它们通常已安装,并且可以通过PATH
变量找到。
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 thePATH
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_DIR
或 mylib_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/v3.6/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/v3.6/command/find_library.html
这篇关于CMake找不到includes / libraries的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!