undefined reference to `cv::imread(cv::String const&, int)'

记录一次很诡异的错误,由于粗心,在使用opencv中的cv::imread函数的时候,在CMakeLists.txt中忘记添加库连接

target_link_libraries( opencv_test ${OpenCV_LIBS} )

编译出错

CMakeFiles/opencv_test.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x53): undefined reference to `cv::imread(cv::String const&, int)'
main.cpp:(.text+0xa5): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
main.cpp:(.text+0xcd): undefined reference to `cv::waitKey(int)'
CMakeFiles/opencv_test.dir/main.cpp.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/opencv_test.dir/main.cpp.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/opencv_test.dir/main.cpp.o: In function `cv::Mat::~Mat()':
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
CMakeFiles/opencv_test.dir/main.cpp.o: In function `cv::Mat::release()':
main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
CMakeFiles/opencv_test.dir/build.make:83: recipe for target 'opencv_test' failed
make[2]: *** [opencv_test] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/opencv_test.dir/all' failed
make[1]: *** [CMakeFiles/opencv_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
 

你可能感兴趣的:(OpenCV,图像处理,C++)