2

I can't get my CLion to build the project because of a weird error upon saving my CMakeLists and/or building the project: Error: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.

Source file:

#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;
}

My CMakeLists.txt: cmake_minimum_required(VERSION 3.3) project(Test) find_package( OpenCV REQUIRED ) add_executable( Test main.cpp ) target_link_libraries( Test ${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

The fact is when I manually cmake . & make (with all the same CMakeLists file) my project from console it works just fine with no errors.

OpenCV version: 2.4.11-1 (arch linux) CLion: latest.

OpenCVConfig.cmake difference compared to git version: https:// www.diffchecker. com/vtmmiu1w

Manual build output:

[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
Morgoth
  • 4,935
  • 8
  • 40
  • 66
12sd
  • 81
  • 1
  • 6
  • I am stuck, I tried nearly everything possible. There was a similar problem here on SO, but it wasn't solved. – 12sd Sep 05 '15 at 08:36
  • When build project manually, you do *in-source build* (run cmake from source directory), don't you? It may conflict with *out-of-source* build, performed by CLion. – Tsyvarev Sep 05 '15 at 10:40
  • @Tsyvarev yes, but I can't figure out what's the difference of searching CMake packages between in-source and out-of-source. – 12sd Sep 05 '15 at 10:53
  • @Tsyvarev and I tried cleaning the results of in-source build, leaving just source file and CMakeLists, but CLion build fails the same way, and in-source build works fine. That's why I called it weird. – 12sd Sep 05 '15 at 10:58
  • Probably, CLion calls `cmake` with some additional parameters. What value of `OpenCV_DIR` variable in your (successfull) manual build? It can be found in `CMakeCache.txt` file. – Tsyvarev Sep 05 '15 at 11:03
  • @Tsyvarev `OpenCV_DIR:PATH=/usr/share/opencv` – 12sd Sep 05 '15 at 11:08
  • Is your `/usr/share/opencv/OpenCVConfig.cmake` file similar to this one: https://github.com/Itseez/opencv/blob/master/cmake/OpenCVConfig.cmake? If so, what output of successfull `cmake` call? (You can edit your question for add this output). – Tsyvarev Sep 05 '15 at 11:27
  • @Tsyvarev added a link to diff of the git version and mine, also added an output of manual build. Sorrym can't post more than two links, spaces added. – 12sd Sep 05 '15 at 11:33
  • @Tsyvarev also, tried to use the .cmake config from github, the error is absolutely the same and also complains about no compatible binaries found. – 12sd Sep 05 '15 at 11:37
  • Your original `OpenCVConfig.cmake` sets `OpenCV_FOUND` to false only in Android case. This correlates in some sence with "no compatible binaries found" with other `OpenCVConfig.cmake`. Is your CLion is configured(installed) properly for Linux? (Can you build and execute simple program with it?) – Tsyvarev Sep 05 '15 at 11:53
  • @Tsyvarev yes, helloworlds and etc. work fine. – 12sd Sep 05 '15 at 12:07
  • So, I has no idea about origin of that error. You can add output commands (`message`, `file(WRITE)`, etc.) into `/usr/share/opencv/OpenCVConfig.cmake` to see what is actually a reason why it set `OpenCV_FOUND` to false. Nice fact is that you can compare that ouput with one obtained from successfull manual build. – Tsyvarev Sep 05 '15 at 12:19
  • @Tsyvarev I made a workaround (see the answer). Thanks for your assistance! – 12sd Sep 05 '15 at 12:50

1 Answers1

5

I don't know what really happened, but I've added a line that manually sets the OpenCV_FOUND to 1 into OpenCVConfig.cmake and everything works fine:

set(OpenCV_FOUND 1)

12sd
  • 81
  • 1
  • 6