linux下Opencv的简单程序:
#include "highgui.h"
using namespace cv;
int main (int argc, char const* argv[])
{
Mat src;
src=imread("lena.jpg");
namedWindow("src");
imshow("src",src);
waitKey(0);
return 0;
}
编译方法:
1、 g++ test.cpp `pkg-config opencv --libs --cflags opencv` 编译没问题,正确。也能够执行
2、 g++ `pkg-config opencv --libs --cflags opencv` test.cpp 编译错误,不成功。
错误提示:
tmp/ccI1amzW.o: In function `main':
test.cpp:(.text+0x5e): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0xcf): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0xfa): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
test.cpp:(.text+0x131): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
test.cpp:(.text+0x153): undefined reference to `cv::waitKey(int)'
/tmp/ccI1amzW.o: In function `cv::Mat::~Mat()':
test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x2b): undefined reference to `cv::fastFree(void*)'
/tmp/ccI1amzW.o: In function `cv::Mat::operator=(cv::Mat const&)':
test.cpp:(.text._ZN2cv3MataSERKS0_[cv::Mat::operator=(cv::Mat const&)]+0xf2): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccI1amzW.o: In function `cv::Mat::release()':
test.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3b): undefined reference to `cv::Mat::deallocate()'
collect2: ld 返回 1
请指点。