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

成功!

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值