Linux 编译 OpenCV 出现 ‘cv::imread(std::__cxx11:: 错误的解决方案

本来在CentOS下编译还挺正常的,换Ubuntu后我在测试 OpenCV 的时候却发现编译不了:
/tmp/cceUgR20.o:在函数‘main’中:

test.c:(.text+0xb1):对‘cv::imread(std::__cxx11::basic_string, std::char_traits, std::allocator > const&, int)’未定义的引用
test.c:(.text+0xc7):对‘cv::_InputArray::_InputArray(cv::Mat const&)’未定义的引用
test.c:(.text+0xe0):对‘cv::imshow(std::__cxx11::basic_string, std::char_traits, std::allocator > const&, cv::_InputArray const&)’未定义的引用
test.c:(.text+0xea):对‘cv::waitKey(int)’未定义的引用
/tmp/cceUgR20.o:在函数‘cv::Mat::~Mat()’中:
test.c:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39):对‘cv::fastFree(void*)’未定义的引用
/tmp/cceUgR20.o:在函数‘cv::Mat::release()’中:
test.c:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47):对‘cv::Mat::deallocate()’未定义的引用
collect2: error: ld returned 1 exit status

我一直以为是C++11或者g++版本的原因,看到:
http://forum.ubuntu.com.cn/viewtopic.php?f=48&t=377522 提出:

g++ pkg-config --cflags --libs opencv lena.cpp -o lena

这样会编译失败,而

g++ lena.cpp pkg-config --cflags --libs opencv -o lena

这样就会成功。试了一下果然如此。真是奇怪。

另外还可能是:
http://blog.csdn.net/chengy35/article/details/42738335

你可能感兴趣的:(opencv)