我知道这个问题有很多重复,但是因为没有任何答案适合我,所以我宁愿问另外一个问题。
我的项目不会用CMake编译:
发现包configuration文件:/usr/share/OpenCV/OpenCVConfig.cmake,但它将OpenCV_FOUND设置为FALSE,因此包“OpenCV”被认为是未find。
我的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 /包含/ OpenCV的
如果有人有解决办法,我很乐意接受。
好的,我明白了。 太糟糕了,我一直坚持这一点。
我正在使用CLion,所以解决方案可能会有所不同,但您只需要删除缓存并重新加载项目(我个人去了Tools> CMake> Delete cache and Reload project)。
如果命令行工作和CMake不,我想这是你所要做的。
我希望最终能够帮助那些有这样一个愚蠢的错误的人。