Cmake编译错误--怕忘,遇到些特殊的问题记下来-TODO

Q1:Could not find a package configuration file

 By not providing "FindNLOPT.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "NLOPT", but
  CMake did not find one.
  
  Could not find a package configuration file provided by "NLOPT" with any of
  the following names:
    NLOPTConfig.cmake
    nlopt-config.cmake
    
  Add the installation prefix of "NLOPT" to CMAKE_PREFIX_PATH or set
  "NLOPT_DIR" to a directory containing one of the above files.  If "NLOPT"
  provides a separate development package or SDK, be sure it has been
  installed.

R1:首先请确保是否是因为缺包引起的。是的话安装对应包,不是则找到xxx.cmake的存放位置

在CMakelist.txt中添加xxx.cmake所在的路径到查找路径。
解决以上报错的两种方法:

  1. 添加 set (CMAKE_PREFIX_PATH "pathtoxxx.cmake")
  2. 添加 list(APPEND CMAKE_FIND_ROOT_PATH "pathtoxxx.cmake")
    如果直接xxx.cmake直接在项目目录下,添加list(APPEND CMAKE_FIND_ROOT_PATH ${PROJECT_SOURCE_DIR})即可。

CMAKE_SOURCE_DIR does indeed refer to the folder where the top-level CMakeLists.txt is defined.
PROJECT_SOURCE_DIR refers to the folder of the CMakeLists.txt containing the most recent project() command.

你可能感兴趣的:(Cmake编译错误--怕忘,遇到些特殊的问题记下来-TODO)