Ask Your Question
0

OpenCV 3.1.0 won't compile with CMake

asked 2016-04-14 06:17:09 -0600

Razakhel gravatar image

updated 2016-04-14 06:20:21 -0600

Hi there.

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" )

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} )

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):

-I/usr/include/opencv

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-04-14 07:11:36 -0600

Razakhel gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-14 06:17:09 -0600

Seen: 1,738 times

Last updated: Apr 14 '16