gpt4 book ai didi

c++ - OpenCV CLion (Cmake) 链接问题 - cmake 报告一个奇怪的错误

转载 作者:搜寻专家 更新时间:2023-10-31 00:59:54 26 4
gpt4 key购买 nike

由于在保存我的 CMakeLists 和/或构建项目时出现奇怪的错误,我无法让我的 CLion 构建项目:
错误:找到包配置文件:
/usr/share/opencv/OpenCVConfig.cmake
但它将 OpenCV_FOUND 设置为 FALSE,因此包“OpenCV”被视为未找到。

源文件:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{
Mat image;
image = imread( "lena.jpg", 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}

我的CMakeLists.txt:
cmake_minimum_required(版本 3.3)
项目(测试)
find_package(需要 OpenCV)
add_executable(测试main.cpp)
target_link_libraries(测试 ${OpenCV_LIBS} )

$ pkg-config --cflags opencv
-I/usr/include/opencv

$ pkg-config --libs opencv
-L/lib64 -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -ltbb -lGL -lGLU -lrt -lpthread -lm -ldl

事实是当我手动 cmake 时。 & make(使用所有相同的 CMakeLists 文件)我的项目从控制台运行正常,没有错误

OpenCV 版本:2.4.11-1 (arch linux)CLion:最新。

OpenCVConfig.cmake 与 git 版本的区别:https://www.diffchecker。 com/vtmmiu1w

手动构建输出:

[dobegor@dobegor-pc Test]$ cmake .
-- The C compiler identification is GNU 5.2.0
-- The CXX compiler identification is GNU 5.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dobegor/ClionProjects/Test
[dobegor@dobegor-pc Test]$ make
Scanning dependencies of target Test
[ 50%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
[100%] Linking CXX executable Test
[100%] Built target Test

最佳答案

我不知道到底发生了什么,但我在 OpenCVConfig.cmake 中添加了一行手动将 OpenCV_FOUND 设置为 1 并且一切正常:

设置(OpenCV_FOUND 1)

关于c++ - OpenCV CLion (Cmake) 链接问题 - cmake 报告一个奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32407200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com