0

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
TyN101
  • 43
  • 1
  • 10
  • possible duplicate: [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – m.s. Oct 19 '15 at 14:42

1 Answers1

0

You have to link your binary against OpenCV... Assuming you properly installed OpenCV this can be done with:

g++ -o cppTest cppTest.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc
Hamdor
  • 381
  • 4
  • 15