opencv2.4.0程序运行代码为g++`pkg config--cflags--libs opencv`facedetect.cpp-o opencv

opencv2.4.0程序运行代码为g++`pkg config--cflags--libs opencv`facedetect.cpp-o opencv,opencv,Opencv,我是OpenCV的新手,我已经在Ubuntu上安装了它。当我试图运行存储在opencv-2.4.0/samples/c中的示例程序facedetect.cpp时,我无法让它工作 我尝试通过以下命令运行它: g++ \`pkg-config --cflags --libs opencv\` facedetect.cpp -o opencv 但遇到以下错误: /tmp/ccKQ8N39.o: In function `main': facedetect.cpp:(.text+0x1b9): und

我是OpenCV的新手,我已经在Ubuntu上安装了它。当我试图运行存储在
opencv-2.4.0/samples/c
中的示例程序facedetect.cpp时,我无法让它工作

我尝试通过以下命令运行它:

g++ \`pkg-config --cflags --libs opencv\` facedetect.cpp -o opencv
但遇到以下错误:

/tmp/ccKQ8N39.o: In function `main':
facedetect.cpp:(.text+0x1b9): undefined reference to `cv::CascadeClassifier::CascadeClassifier()'
facedetect.cpp:(.text+0x1c7): undefined reference to `cv::CascadeClassifier::CascadeClassifier()'
facedetect.cpp:(.text+0x3ac): undefined reference to `cv::CascadeClassifier::load(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
facedetect.cpp:(.text+0x589): undefined reference to `cv::CascadeClassifier::load(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
facedetect.cpp:(.text+0x674): undefined reference to `cvCreateCameraCapture'
facedetect.cpp:(.text+0x744): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
facedetect.cpp:(.text+0x799): undefined reference to `cvCreateFileCapture'
facedetect.cpp:(.text+0x824): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
facedetect.cpp:(.text+0x8b3): undefined reference to `cvNamedWindow'
facedetect.cpp:(.text+0x8f6): undefined reference to `cvQueryFrame'
facedetect.cpp:(.text+0x91c): undefined reference to `cv::Mat::Mat(_IplImage const*, bool)'
facedetect.cpp:(.text+0x97d): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facedetect.cpp:(.text+0x995): undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
facedetect.cpp:(.text+0x9af): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facedetect.cpp:(.text+0x9c7): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
facedetect.cpp:(.text+0x9e7): undefined reference to `cv::flip(cv::_InputArray const&, cv::_OutputArray const&, int)'
facedetect.cpp:(.text+0xa1f): undefined reference to `cv::waitKey(int)'
facedetect.cpp:(.text+0xa3b): undefined reference to `cv::waitKey(int)'
facedetect.cpp:(.text+0xa49): undefined reference to `cvReleaseCapture'
facedetect.cpp:(.text+0xabf): undefined reference to `cv::waitKey(int)'
facedetect.cpp:(.text+0xbfe): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
facedetect.cpp:(.text+0xc90): undefined reference to `cv::waitKey(int)'
facedetect.cpp:(.text+0xd33): undefined reference to `cvDestroyWindow'
facedetect.cpp:(.text+0xd46): undefined reference to `cv::CascadeClassifier::~CascadeClassifier()'
facedetect.cpp:(.text+0xd54): undefined reference to `cv::CascadeClassifier::~CascadeClassifier()'
facedetect.cpp:(.text+0xeaf): undefined reference to `cv::CascadeClassifier::~CascadeClassifier()'
facedetect.cpp:(.text+0xec1): undefined reference to `cv::CascadeClassifier::~CascadeClassifier()'
/tmp/ccKQ8N39.o: In function `detectAndDraw(cv::Mat&, cv::CascadeClassifier&, cv::CascadeClassifier&, double)':
facedetect.cpp:(.text+0x1278): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facedetect.cpp:(.text+0x128d): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
facedetect.cpp:(.text+0x12b5): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
facedetect.cpp:(.text+0x12e8): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facedetect.cpp:(.text+0x1300): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
facedetect.cpp:(.text+0x1333): undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
facedetect.cpp:(.text+0x134b): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facedetect.cpp:(.text+0x1363): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
facedetect.cpp:(.text+0x137b): undefined reference to `cv::equalizeHist(cv::_InputArray const&, cv::_OutputArray const&)'
facedetect.cpp:(.text+0x1380): undefined reference to `cvGetTickCount'
facedetect.cpp:(.text+0x140e): undefined reference to `cvGetTickCount'
facedetect.cpp:(.text+0x142b): undefined reference to `cvGetTickFrequency'
facedetect.cpp:(.text+0x160b): undefined reference to `cv::circle(cv::Mat&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)'
facedetect.cpp:(.text+0x187e): undefined reference to `cv::circle(cv::Mat&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)'
facedetect.cpp:(.text+0x1959): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
facedetect.cpp:(.text+0x1993): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/tmp/ccKQ8N39.o: In function `cv::Mat::~Mat()':
facedetect.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x2b): undefined reference to `cv::fastFree(void*)'
/tmp/ccKQ8N39.o: In function `cv::Mat::operator=(cv::Mat const&)':
facedetect.cpp:(.text._ZN2cv3MataSERKS0_[cv::Mat::operator=(cv::Mat const&)]+0xf2): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccKQ8N39.o: In function `cv::Mat::create(int, int, int)':
facedetect.cpp:(.text._ZN2cv3Mat6createEiii[cv::Mat::create(int, int, int)]+0x81): undefined reference to `cv::Mat::create(int, int const*, int)'
/tmp/ccKQ8N39.o: In function `cv::Mat::release()':
facedetect.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3b): undefined reference to `cv::Mat::deallocate()'
/tmp/ccKQ8N39.o: In function `cv::Mat::operator()(cv::Rect_<int> const&) const':
facedetect.cpp:(.text._ZNK2cv3MatclERKNS_5Rect_IiEE[cv::Mat::operator()(cv::Rect_<int> const&) const]+0x1b): undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)'
collect2: ld returned 1 exit status
/tmp/ccKQ8N39.o:在函数“main”中:
facedetect.cpp:(.text+0x1b9):对“cv::CascadeClassifier::CascadeClassifier()”的未定义引用
facedetect.cpp:(.text+0x1c7):对“cv::CascadeClassifier::CascadeClassifier()”的未定义引用
facedetect.cpp:(.text+0x3ac):对“cv::CascadeClassifier::load(std::basic_字符串常量&)”的未定义引用
facedetect.cpp:(.text+0x589):对“cv::CascadeClassifier::load(std::basic_字符串常量&)”的未定义引用
facedetect.cpp:(.text+0x674):对“cvCreateCameraCapture”的未定义引用
facedetect.cpp:(.text+0x744):对“cv::imread(std::basic_string const&,int)”的未定义引用
facedetect.cpp:(.text+0x799):对“cvCreateFileCapture”的未定义引用
facedetect.cpp:(.text+0x824):对'cv::imread(std::basic_string const&,int)'的未定义引用
facedetect.cpp:(.text+0x8b3):未定义对“cvNamedWindow”的引用
facedetect.cpp:(.text+0x8f6):对“cvQueryFrame”的未定义引用
facedetect.cpp:(.text+0x91c):对“cv::Mat::Mat(_iplimageconst*,bool)”的未定义引用
facedetect.cpp:(.text+0x97d):对“cv::\u OutputArray::\u OutputArray(cv::Mat&)”的未定义引用
facedetect.cpp:(.text+0x995):对“cv::Mat::copyTo(cv::_outputarrayconst&)const”的未定义引用
facedetect.cpp:(.text+0x9af):对“cv::\u OutputArray::\u OutputArray(cv::Mat&)”的未定义引用
facedetect.cpp:(.text+0x9c7):对“cv::_InputArray::_InputArray(cv::Mat const&)”的未定义引用
facedetect.cpp:(.text+0x9e7):对“cv::flip(cv:_inputarrayconst&,cv:_outputarrayconst&,int)”的未定义引用
facedetect.cpp:(.text+0xa1f):对“cv::waitKey(int)”的未定义引用
facedetect.cpp:(.text+0xa3b):对“cv::waitKey(int)”的未定义引用
facedetect.cpp:(.text+0xa49):对“cvReleaseCapture”的未定义引用
facedetect.cpp:(.text+0xabf):对“cv::waitKey(int)”的未定义引用
facedetect.cpp:(.text+0xbfe):对“cv::imread(std::basic_string const&,int)”的未定义引用
facedetect.cpp:(.text+0xc90):对“cv::waitKey(int)”的未定义引用
facedetect.cpp:(.text+0xd33):对“cvDestroyWindow”的未定义引用
facedetect.cpp:(.text+0xd46):对“cv::CascadeClassifier::~CascadeClassifier()”的未定义引用
facedetect.cpp:(.text+0xd54):对“cv::CascadeClassifier::~CascadeClassifier()”的未定义引用
facedetect.cpp:(.text+0xeaf):对“cv::CascadeClassifier::~CascadeClassifier()”的未定义引用
facedetect.cpp:(.text+0xec1):未定义对“cv::CascadeClassifier::~CascadeClassifier()”的引用
/tmp/ccKQ8N39.o:在函数“detectAndDraw(cv::Mat&,cv::CascadeClassifier&,cv::CascadeClassifier&,double)”中:
facedetect.cpp:(.text+0x1278):对“cv::\u OutputArray::\u OutputArray(cv::Mat&)”的未定义引用
facedetect.cpp:(.text+0x128d):对“cv::\u InputArray::\u InputArray(cv::Mat const&)”的未定义引用
facedetect.cpp:(.text+0x12b5):对“cv::cvtColor(cv:_inputarrayconst&,cv:_outputarrayconst&,int,int)”的未定义引用
facedetect.cpp:(.text+0x12e8):对“cv::\u OutputArray::\u OutputArray(cv::Mat&)”的未定义引用
facedetect.cpp:(.text+0x1300):对“cv::_InputArray::_InputArray(cv::Mat const&)”的未定义引用
facedetect.cpp:(.text+0x1333):对“cv::resize(cv:_inputarrayconst&,cv:_outputarrayconst&,cv::Size,double,double,int)”的未定义引用
facedetect.cpp:(.text+0x134b):对“cv::\u OutputArray::\u OutputArray(cv::Mat&)”的未定义引用
facedetect.cpp:(.text+0x1363):对“cv::\u InputArray::\u InputArray(cv::Mat const&)”的未定义引用
facedetect.cpp:(.text+0x137b):对“cv::equalizeHist(cv:_InputArrayConst&,cv:_OutputarrayConst&)”的未定义引用
facedetect.cpp:(.text+0x1380):对“cvGetTickCount”的未定义引用
facedetect.cpp:(.text+0x140e):对“cvGetTickCount”的未定义引用
facedetect.cpp:(.text+0x142b):对“cvGetTickFrequency”的未定义引用
facedetect.cpp:(.text+0x160b):对“cv::circle(cv::Mat&,cv::Point,int,cv::Scalar_uu&,int,int,int)”的未定义引用
facedetect.cpp:(.text+0x187e):未定义对“cv::circle(cv::Mat&,cv::Point,int,cv::Scalar_uu&,int,int,int)”的引用
facedetect.cpp:(.text+0x1959):对“cv::\u InputArray::\u InputArray(cv::Mat const&)”的未定义引用
facedetect.cpp:(.text+0x1993):对“cv::imshow(std::basic_string const&,cv:_inputarrayconst&)”的未定义引用
/tmp/ccKQ8N39.o:在函数“cv::Mat::~Mat()”中:
facedetect.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x2b):未定义对“cv::fastFree(void*)”的引用
/tmp/ccKQ8N39.o:在函数“cv::Mat::operator=(cv::Mat const&)”中:
facedetect.cpp:(.text.\u ZN2cv3MataSERKS0.[cv::Mat::operator=(cv::Mat const&)]+0xf2):未定义对“cv::Mat::copySize(cv::Mat const&)”的引用
/tmp/ccKQ8N39.o:在函数“cv::Mat::create(int,int,int)”中:
facedetect.cpp:(.text._zn2cv3mat6createeii[cv::Mat::create(int,int,int)]+0x81):对“cv::Mat::create(int,int const*,int)”的未定义引用
/tmp/ccKQ8N39.o:在函数'cv::Mat::release()'中:
facedetect.cpp:(.text.ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3b):未定义对“cv::Mat::deallocate()”的引用
/tmp/ccKQ8N39.o:在函数'cv::Mat::operator()(cv::Rect_uu&)const'中:
facedetect.cpp:(.text._ZNK2cv3MatclERKNS_5Rect_IiEE[cv::Mat::operator()(cv::Rect\uuuu常量&)const]+0x1b):对“cv::Mat::Mat::Mat(cv::Mat const&,cv::Rect\uu常量&)”的未定义引用
collect2:ld返回了1个退出状态

如何解决此问题?

在这里,您可以接受解决问题的答案,并对您认为有用的答案进行投票。:)它将帮助其他面临同样问题的人。我可以知道为什么将pkg config命令放在末尾会起作用吗?我找到了一个解释。在这里,你是c
g++ facedetect.cpp -o opencv `pkg-config --cflags --libs opencv`