[英]error compiling c++ opencv application on Raspberry Pi
最近几天,我一直在尝试解决我在opencv网上发现的一个简短示例程序时遇到的错误。 可以在下面找到该应用程序的代码,下面是控制台命令和错误。 任何和所有帮助表示赞赏。
.cpp文件:
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(){
Mat img = imread("/home/pi/opencv/testPic.jpg",CV_LOAD_IMAGE_COLOR);
imshow("opencvtest",img);
waitKey(0);
return 0;
}
控制台命令和错误:
pi@LaserPhysics_RasPi ~/opencv $ g++ -o cppTest cppTest.cpp -I/usr/local/include/
/tmp/ccA0pvw2.o: In function `main':
cppTest.cpp:(.text+0x30): undefined reference to `cv::imread(cv::String const&, int)'
cppTest.cpp:(.text+0x74): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
cppTest.cpp:(.text+0x94): undefined reference to `cv::waitKey(int)'
/tmp/ccA0pvw2.o: In function `cv::String::String(char const*)':
cppTest.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x50): undefined reference to `cv::String::allocate(unsigned int)'
/tmp/ccA0pvw2.o: In function `cv::String::~String()':
cppTest.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccA0pvw2.o: In function `cv::Mat::~Mat()':
cppTest.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3c): undefined reference to `cv::fastFree(void*)'
/tmp/ccA0pvw2.o: In function `cv::Mat::release()':
cppTest.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x68): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
您必须将二进制文件与OpenCV链接...假设您已正确安装OpenCV,则可以使用以下方法完成:
g++ -o cppTest cppTest.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.