gpt4 book ai didi

c++ - OpenCV 3.1.0 无法使用 CMake 进行编译

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:07:25 24 4
gpt4 key购买 nike

我知道这个问题有很多假设的重复,但由于没有一个答案对我有用,我宁愿问另一个问题。

我的项目无法使用 CMake 进行编译:

Found package configuration file: /usr/share/OpenCV/OpenCVConfig.cmake but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be NOT FOUND.

我的CMakeLists.txt如下:

cmake_minimum_required( VERSION 2.8 )
project( Tests )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )

if(WIN32)
# set( CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH} C:\\OpenCV" )
set( OpenCV_DIR "C:\\OpenCV\\build" )
elseif(UNIX)
set( OpenCV_DIR "/usr/share/OpenCV" )
set( PKG_CONFIG_PATH "/usr/lib/pkgconfig" )
endif()

find_package( OpenCV REQUIRED )
if( OpenCV_FOUND )
message( "Found OpenCV" )
message( "Includes: " ${OpenCV_INCLUDE_DIRS} )
else()
message( "OpenCV not found, woot" )
endif( OpenCV_FOUND )

add_executable( Test ShapeRecognition/prog.cpp )
target_link_libraries( Test ${OpenCV_LIBS} )

错误发生在 find_package(OpenCV REQUIRED) 行,因此无论如何都不会显示以下消息。

但是在控制台中编译时,使用命令:

g++ -o prog -std=c++11 `pkg-config --libs --cflags opencv` prog.cpp 

编译没有问题,程序可以完美启动。

命令“pkg-config --libs opencv”给我(有点长,我同意):

-lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core

命令“pkg-config --cflags opencv”只是给我(CMAKE_INSTALL_PREFIX 设置为/usr):

-I/usr/include/opencv

如果有人有解决方案,我很乐意接受。

最佳答案

好的,我想通了。太糟糕了,我已经坚持了这么久。

我使用的是 CLion,因此解决方案可能有所不同,但您所要做的就是删除缓存并重新加载项目(我个人前往工具 > CMake > 删除缓存并重新加载项目)。

如果命令行有效而 CMake 无效,我想这就是您所要做的。

我希望它最终能帮助那些犯过如此愚蠢错误的人。

关于c++ - OpenCV 3.1.0 无法使用 CMake 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36622162/

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