opencv安装完成也有一阵子了,我才用的是编译安装,环境Ubuntu16.04 LTS。今天有时间想自己写一点程序,却发现编译不过
代码如下,打开命令行中输入的文件名并展示在窗口中
// openpicture.cpp
#include "opencv2/highgui/highgui.hpp"
int main(int argc, char** argv)
{
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
return 0;
}
编译的时候报错,显示所有调用过的cv函数都未定义
/tmp/cczaBtDO.o:在函数‘main’中:
openpic.cpp:(.text+0x32):对‘cvLoadImage’未定义的引用
openpic.cpp:(.text+0x45):对‘cvNamedWindow’未定义的引用
openpic.cpp:(.text+0x56):对‘cvShowImage’未定义的引用
openpic.cpp:(.text+0x60):对‘cvWaitKey’未定义的引用
openpic.cpp:(.text+0x6c):对‘cvReleaseImage’未定义的引用
openpic.cpp:(.text+0x76):对‘cvDestroyWindow’未定义的引用
collect2: error: ld returned 1 exit status
google一下,大概明白了是程序链接的时候找不到源码,下面开始解决问题
opencv在ubuntu下是通过调用早已编译好的动态链接库.so文件来生成程序的,通过g++ 的编译控制选项也许可以制定编