问题
I have written the following code in C++ which use openCV to be run in Beaglebone:
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
CvCapture *capture = 0;
Mat img3;
Mat src;
capture = cvCaptureFromCAM(0);
vector<int> p;
p.push_back(CV_IMWRITE_PNG_COMPRESSION);
p.push_back(9);
while (1) {
img3 = cvQueryFrame(capture);
cvtColor(img3, img3, CV_BGR2GRAY);
pyrDown(img3, src, Size( img3.cols/2, img3.rows/2 ) );
if (!imwrite("/home/root/Desktop/website/fig3bmp.bmp",src,p)) {
printf("mat not saved!!!\n");
}
}
return 0;
}
I have tried compiling the code using: "g++ -o CamaraTest CamaraTest.cpp", but it does not work, and all the errors I get are something like: "undefined reference to: cv... "
I have already checked that the files "cv.h" and "highgui.h" are in the directory "/usr/include/opencv".
How can I compile this code? Any suggestion would help a lot.
Thanks in advance.
gus.
回答1:
These "undefined reference to: cv... " messages are linker errors due to missing libraries - you need to link with the OpenCV libraries in your g++ command line, e.g.:
$ g++ -Wall -g -o CamaraTest CamaraTest.cpp `pkg-config --cflags --libs opencv`
来源:https://stackoverflow.com/questions/14565876/compiling-c-code-using-opencv-in-beaglebone