ubuntu12.04 安装opencv 并解决undefined reference to `cvLoadImage’的问题

ubuntu12.04 安装opencv

1 编译环境 sudo apt-get install build-essential

安装GTK环境  sudo apt-get install libgtk2.0-dev  

编译GTK程序时自动找出头文件及库文件位置  sudo apt-get install pkg-config  

4 安装cmake sudo apt-get install cmake

5 下载源码 opencv2.4 并解压,进入opencv2.4

6  mkdir release ;cd release

7 生成makefile(..代表父目录)  cmake ..  

8 编译安装 make;sudo make install 

9 配置必要的库 sudo gedit /etc/ld.so.conf.d/opencv.conf

  添加  /usr/local/lib   这句命令到文件中(文件或许是空的,不影响)

10  sudo ldconfig

11  sudo gedit /etc/bash.bashrc,添加下面两行到文件的末尾并保存。

1 PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
2 export PKG_CONFIG_PATH

 

测试:gcc `pkg-config opencv --libs --cflags opencv` -o main main.c

如果出现:

opencv1.c:(.text+0×23): undefined reference to `cvLoadImage’
opencv1.c:(.text+0×36): undefined reference to `cvNamedWindow’
opencv1.c:(.text+0×47): undefined reference to `cvShowImage’
opencv1.c:(.text+0×51): undefined reference to `cvWaitKey’
opencv1.c:(.text+0x5d): undefined reference to `cvReleaseImage’
opencv1.c:(.text+0×67): undefined reference to `cvDestroyWindow’
collect2: ld returned 1 exit status

则用:gcc `pkg-config --cflags opencv` -o main main.c `pkg-config --libs opencv`

你可能感兴趣的:(linux,linux,opencv,ubuntu,C++)