I want to setup OpenCV on windows for the CLion IDE. I tried with OpenCV 3.1 and 2.4 with the same result. I have Windows 10 64 bits. CLion is using the cygwin environement.
What I did so far:
1. Downloaded the exe from OpenCV and runned it (it extracted a package). My path is E:/opencv
2. Added OpenCV_DIR variable and added it to path
3. Added this to my project CMakeLists.txt:
set(OpenCV_LIB_PATH E:/opencv/build/x64/vc12/lib)
set(OpenCV_LIB_DIR E:/opencv/build/x64/vc12/lib)
set(OpenCV_LIBS E:/opencv/build/x64/vc12/lib)
set(CMAKE_PREFIX_PATH E:/opencv/build)
set(OpenCV_DIR E:/opencv/build/x64/vc12)
include_directories(E:/opencv/build/include)
FIND_PACKAGE(OpenCV REQUIRED)
target_link_libraries(good ${OpenCV_LIBS} )
I managed to use the OpenCV Mat in my program (The libraries are visible) but I receive an error when trying to open an image.
My program is: (just an example)
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
string imageName("../data/test.png");
if( argc > 1)
{
imageName = argv[1];
}
Mat image;
image = imread(imageName.c_str(), IMREAD_COLOR);
if( image.empty() )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );
waitKey(0);
return 0;
}
The problem is: When i run the project i get the error:
/cygdrive/d/projects/good/src/main.cpp:17: undefined reference to `cv::imread(std::string const&, int)'
/cygdrive/d/projects/good/src/main.cpp:17:(.text+0xc4): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::imread(std::string const&, int)'
/cygdrive/d/projects/good/src/main.cpp:23: undefined reference to `cv::namedWindow(std::string const&, int)'
/cygdrive/d/projects/good/src/main.cpp:23:(.text+0x177): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::namedWindow(std::string const&, int)'
/cygdrive/d/projects/good/src/main.cpp:24: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
/cygdrive/d/projects/good/src/main.cpp:24:(.text+0x1a8): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::_InputArray::_InputArray(cv::Mat const&)'
/cygdrive/d/projects/good/src/main.cpp:24: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
/cygdrive/d/projects/good/src/main.cpp:24:(.text+0x1ed): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::imshow(std::string const&, cv::_InputArray const&)'
/cygdrive/d/projects/good/src/main.cpp:25: undefined reference to `cv::waitKey(int)'
/cygdrive/d/projects/good/src/main.cpp:25:(.text+0x215): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::waitKey(int)'
CMakeFiles/good.dir/src/main.cpp.o: In function `cv::Mat::~Mat()':
E:/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
E:/opencv/build/include/opencv2/core/mat.hpp:278:(.text$_ZN2cv3MatD1Ev[_ZN2cv3MatD1Ev]+0x36): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::fastFree(void*)'
CMakeFiles/good.dir/src/main.cpp.o: In function `cv::Mat::operator=(cv::Mat const&)':
E:/opencv/build/include/opencv2/core/mat.hpp:298: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
E:/opencv/build/include/opencv2/core/mat.hpp:298:(.text$_ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x110): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::Mat::copySize(cv::Mat const&)'
CMakeFiles/good.dir/src/main.cpp.o: In function `cv::Mat::release()':
E:/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
E:/opencv/build/include/opencv2/core/mat.hpp:367:(.text$_ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x44): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::Mat::deallocate()'
Thank you very much.