Skip to content

OpenCV 3.1.0 won’t compile with CMake

I know there are many supposed duplicates for this matter, but since none of the answers worked for me I’d rather ask another question.

My project won’t compile with 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.

My CMakeLists.txt is as follows:

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

    set( OpenCV_DIR "C:\OpenCV\build" )
    set( OpenCV_DIR "/usr/share/OpenCV" )
    set( PKG_CONFIG_PATH "/usr/lib/pkgconfig" )

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

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

The error happens on the line find_package(OpenCV REQUIRED), thus none of the messages below are displayed anyway.

BUT while compiling in console, with the command:

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

The compilation happens without a problem, and the program can be launched perfectly fine.

The command “pkg-config –libs opencv” gives me (a bit long, I agree):

-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

The command “pkg-config –cflags opencv” simply gives me (CMAKE_INSTALL_PREFIX is set to /usr):


If anyone has a solution, I’d gladly take it.



Ok so I figured it out. Too bad I’ve been stuck on this for that long.

I am using CLion, so solution may differ, but all you have to do is to delete the cache and reload the project (I personally went to Tools > CMake > Delete cache and Reload project).

If command line works and CMake doesn’t, I guess this is all you have to do.

I hope it will eventually come to help someone else who’d have such a stupid error.

User contributions licensed under: CC BY-SA
6 People found this is helpful