简体   繁体   中英

error compiling c++ opencv application on Raspberry Pi

I have been spending the last few days attempting to address an error I have while compiling a brief example program I found online with opencv. The code for the application can be found below, with the console command and error following. Any and all help is appreciated.

.cpp file:

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

console command and error:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM