#include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main(int argc, char* argv[]) { const char* imagename = "gzh.jpg"; Mat img = imread(imagename); imshow("image", img); waitKey(); return 0;}
znkz@znkz:~/gzh$ g++ test.cpp -o test
error:
/tmp/ccFRpjXB.o:在函数‘main’中: test.cpp:(.text+0x6a):对‘cv::imread(std::string const&, int)’未定义的引用 test.cpp:(.text+0x9e):对‘cv::_InputArray::_InputArray(cv::Mat const&)’未定义的引用 test.cpp:(.text+0xe1):对‘cv::imshow(std::string const&, cv::_InputArray const&)’未定义的引用 test.cpp:(.text+0x109):对‘cv::waitKey(int)’未定义的引用 /tmp/ccFRpjXB.o:在函数‘cv::Mat::~Mat()’中: test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39):对‘cv::fastFree(void*)’未定义的引用 /tmp/ccFRpjXB.o:在函数‘cv::Mat::release()’中: test.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47):对‘cv::Mat::deallocate()’未定义的引用 collect2: error: ld returned 1 exit status
解决:
znkz@znkz:~/gzh$ g++ test.cpp `pkg-config --cflags --libs opencv` -o test
这是链接器问题。
1、
locate iostream
可以定位头文件位置