Prerequisite:
Opencv is already installed.
Source code:
//include high gui headers
#include "opencv2/highgui/highgui.hpp"
//we are using standard and OpenCV namespaces
using namespace cv;
using namespace std;
int main( int argc, const char** argv ){
//create a window named theWindow
namedWindow("theWindow", CV_WINDOW_AUTOSIZE);
//wait user hit some key
waitKey(0);
//destroy window named theWindow
destroyWindow("theWindow");
return 0;
}
Build command:
g++ -o firstcv $(pkg-config --libs --cflags opencv) main.cpp
if error happened.
/tmp/cceyijPd.o: In function `main':
main.cpp:(.text+0x3d): undefined reference to `cv::namedWindow(cv::String const&, int)'
main.cpp:(.text+0x53): undefined reference to `cv::waitKey(int)'
main.cpp:(.text+0x70): undefined reference to `cv::destroyWindow(cv::String const&)'
/tmp/cceyijPd.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cceyijPd.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
It came from a linker, please try :
g++ -o main main.cpp `pkg-config opencv --cflags --libs`
Reference:
Comments
Post a Comment