cmake编译opencv报错

来源:互联网 发布:小金鱼摔炮淘宝 编辑:程序博客网 时间:2024/06/06 17:51

1.
错误
CMakeFiles/opencv_example.dir/example.cpp.o:在函数‘main’中:
example.cpp:(.text+0x12c):对‘cv::imshow(cv::String const&, cv::_InputArray const&)’未定义的引用
example.cpp:(.text+0x21d):对‘cv::imshow(cv::String const&, cv::_InputArray const&)’未定义的引用
CMakeFiles/opencv_example.dir/example.cpp.o:在函数‘drawText(cv::Mat&)’中:
example.cpp:(.text+0x3fe):对‘cv::putText(cv::InputOutputArray const&, cv::String const&, cv::Point, int, double, cv::Scalar_, int, int, bool)’未定义的引用
CMakeFiles/opencv_example.dir/example.cpp.o:在函数‘cv::String::String(char const*)’中:
example.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d):对‘cv::String::allocate(unsigned long)’未定义的引用
CMakeFiles/opencv_example.dir/example.cpp.o:在函数‘cv::String::~String()’中:
example.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14):对‘cv::String::deallocate()’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/opencv_example.dir/build.make:112: recipe for target ‘opencv_example’ failed
make[2]: * [opencv_example] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/opencv_example.dir/all’ failed
make[1]: * [CMakeFiles/opencv_example.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: * [all] Error 2

错误分析:
find_package(OpenCV [版本号] REQUIRED)

find_package(OpenCV 3.3.0 REQUIRED)

问题即可解决
究其原因可能是之前不小心被改成其他版本,导致cmake默认其他版本而无法找到库。

2.
调用include <opencv2/gpu/gpu.hpp>
/usr/include/opencv2/gpu/gpu.hpp:432: error: ‘vector’ does not name a type
CV_EXPORTS void merge(const vector& src, GpuMat& dst, Stream& stream = Stream::Null());
解决办法:
在最前面
加上using namespace std