使用CLion的OpenCV Windows安装程序

我想在Windows上为CLion IDE设置OpenCV。 我用OpenCV 3.1和2.4尝试了相同的结果。 我有Windows 10 64位。 CLion使用cygwin environement。

我到目前为止做了什么:
1.从OpenCV下载exe并运行它(它提取了一个包)。 我的path是E:/ opencv
2.添加OpenCV_DIRvariables并将其添加到path
3.添加到我的项目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} ) 

我设法在我的程序中使用OpenCV Mat(库是可见的),但试图打开图像时收到错误。

我的程序是:(只是一个例子)

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

问题是:当我运行的项目,我得到的错误:

 /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()' 

非常感谢你。

Solutions Collecting From Web of "使用CLion的OpenCV Windows安装程序"