CMake Error at CMakeLists.txt: (FIND_PACKAGE)找不到ncnn包的解决方法

问题描述

demo指路:https://github.com/EdVince/Stable-Diffusion-NCNN
Linux端使用cmake编译文件时,

cd x86/linux
mkdir -p build && cd build
cmake ..
make -j$(nproc)

执行cmake ..命令,报错:

CMake Error at CMakeLists.txt:14 (FIND_PACKAGE):
  By not providing "Findncnn.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "ncnn", but
  CMake did not find one.

  Could not find a package configuration file provided by "ncnn" with any of
  the following names:

    ncnnConfig.cmake
    ncnn-config.cmake

  Add the installation prefix of "ncnn" to CMAKE_PREFIX_PATH or set
  "ncnn_DIR" to a directory containing one of the above files.  If "ncnn"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/home/gaoyi/ldm-ncnn/Stable-Diffusion-NCNN/x86/linux/CMakeFiles/CMakeOutput.log".

问题原因

拉取ncnn的代码库(包括submodule)后没有build and Install,所以cmake时找不到对应的包,只需要让它找到对应的包即可,分为2步:

  1. 生成对应的cmake文件(ncnnConfig.cmakencnn-config.cmake
  2. 设置环境变量(CMAKE_PREFIX_PATH或者ncnn_DIR

解决方法

  1. build and Install ncnn

需要执行以下命令:

cd ncnn
mkdir -p build
cd build
cmake ..

cmake之后继续在build目录下,执行:

make install

发现弹出的信息中有:

这其中的ncnnConfig.cmake、ncnn.cmake就是我们需要找的包,找到上一级目录,右键复制路径

  1. 设置环境变量
export ncnn_DIR=/home/gaoyi/ldm-ncnn/Stable-Diffusion-NCNN/ncnn/build/install/lib/cmake/ncnn

这个环境变量就是上一步复制的路径

  1. 重新运行cmake
cmake ..

看到:

-- Configuring done
-- Generating done
-- Build files have been written to: /home/gaoyi/ldm-ncnn/Stable-Diffusion-NCNN/x86/linux

成功!

猜你喜欢

转载自blog.csdn.net/qq_45510888/article/details/129248757