Linux系统配置opencv(GPU)时出现,find_package(OpenCV REQUIRED)的编译错误

Linux系统配置opencv(GPU)时出现,find_package(OpenCV REQUIRED)的编译错误

在安装opcv-GPU版本时,在cmakelist文件的配置问题出错.导致编译失败。
具体报错警告如下:

问题一:

CMake Error at /usr/local/lib/cmake/opencv4/OpenCVConfig.cmake:86 (find_package):
  By not providing "FindCUDA.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "CUDA", but
  CMake did not find one.

Could not find a package configuration file provided by "CUDA" (requested
  version 11.8) with any of the following names:

    CUDAConfig.cmake
    cuda-config.cmake

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

问题一解决在CMake Error : OpenCV CUDA CMakeLists.txt - CUDA Setup and Installation - NVIDIA Developer Forums

问题一解析:

由于在CMake 3.27版本中不再需要使用该模块或调用find_package(CUDA)来编译CUDA代码,为了解决我最初提出的问题,我简单地将cmake_minimum_required()降低到3.27版之前的任何版本,例如3.26或更低。

问题一解决:

cmake_minimum_required(VERSION 3.26)                        降低指定cmake版本
cmake_minimum_required(VERSION 3.26)

问题二:

解决问题一后,问题二出现,编译器报错如下:

CMake Warning (dev) at /usr/local/lib/cmake/opencv4/OpenCVConfig.cmake:86 (find_package):
  Policy CMP0146 is not set: The FindCUDA module is removed.  Run "cmake
  --help-policy CMP0146" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

问题二解析:

  1. 这个警告是因为在CMake中,FindCUDA模块已经被移除。要解决这个问题,你需要设置CMP0146策略并使用cmake_policy命令来抑制这个警告。你可以在你的CMakeLists.txt文件中添加以下代码:

问题解决:

if(POLICY CMP0146)
    cmake_policy(SET CMP0146 OLD)
endif()
if(POLICY CMP0146)
    cmake_policy(SET CMP0146 OLD)
endif()

最后编译成功通过,可以运行opencv项目代码

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XU磊260

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值