Note for English Readers

If I write the articles in Indonesian, I will write a summary in English so that you can read my articles too. After you read the summary and you feel that you need more information about that, please do not hesitate to contact me via e-mail that can be found in my profile.

Thank you for reading my blogs.

Monday, September 17, 2007

Installing OpenCV from source, especially on x86_64 Linux system that has multilib support

Yesterday, I spent many hours to find out why I could not use OpenCV in Slamd64 after compiling and installing from the source. Finally, I found the problem: something related to multilib support in Slamd64, especially when I configured OpenCV to use GTK+-2.0. In Slamd64 system that has multilib support, it has two version of GTK+-2.0, i.e. 32-bit version and 64-bit version. Until now, I don't understand, when in the configuring process of OpenCV source, why that process "choose" the 32-bit version of GTK+-2.0 instead of 64-bit version, so that, I got error in compiling process and if didn't get error, ld could not link the OpenCV library to my program when I run gcc. I will check later if I have time :)

How to Compile OpenCV from source, especially on x86_64 Linux system that has multilib support
Note for user that doesn't use x86_64 Linux OS: after first step, you can skip the second.
First, make sure ffmpeg has been installed. Read the INSTALL documentation in OpenCV source tree. Other libraries that may be needed such as xine-lib, ieee1394 library (libraw1394 and libdc1394), video for linux (usually already included in kernel), libjpeg, zlib, libpng, libtiff, libjasper, libIlmImf are optional. Make sure to install those libraries before configuring/compiling OpenCV if it's necessary.
Second, to make sure the configuring process of OpenCV source "choose" the 64-bit version of GTK+-2.0, you have to edit 2 lines from the configure file in OpenCV source tree because you cannot add them as options when you type ./configure on bash prompt :(

  • find this line: GTK_LIBS=`$PKG_CONFIG --libs ""gtk+-2.0 gdk-pixbuf-2.0""`
  • change to this (NOTE THAT THE CODE MAY VARY IN YOUR SYSTEM!): GTK_LIBS="-L/usr/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lm -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0"
How to get "-L/usr/lib64 ..."?
$ pkg-config --libs ""gtk+-2.0 gdk-pixbuf-2.0""
You will get: -L/usr/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lm -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0
Copy that line to configure file and change /usr/lib to /usr/lib64.

  • find this line: GTK_CFLAGS=`$PKG_CONFIG --cflags ""gtk+-2.0 gdk-pixbuf-2.0""`
  • change to this (NOTE THAT THE CODE MAY VARY IN YOUR SYSTEM!): GTK_CFLAGS="-DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12"
How to get "-DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 ..."?
$ pkg-config --cflags ""gtk+-2.0 gdk-pixbuf-2.0""
You will get: -DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12
Copy that line to configure file and change /usr/lib/gtk-2.0/include to /usr/lib64/gtk-2.0/include

  • find this line: GTHREAD_LIBS=`$PKG_CONFIG --libs ""gthread-2.0""`
  • change to this: GTHREAD_LIBS="-L/usr/lib64 "`$PKG_CONFIG --libs ""gthread-2.0""`

$ ./configure --with-xine --with-ffmpeg --with-1394libs --with-v4l --with-gtk --without-quicktime
It indicates that OpenCV uses xine, ffmpeg, ieee1394, video for linux, and GTK+-2.0 libraries but disables quicktime library. OpenCV will be installed in default prefix (/usr/local) For detailed options, type ./configure --help
Here is some results of the configure in my laptop:
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking Carbon/Carbon.h usability... no
checking Carbon/Carbon.h presence... no
checking for Carbon/Carbon.h... no
checking for pkg-config... /usr/bin/pkg-config
checking for "gtk+-2.0 gdk-pixbuf-2.0"... yes
checking GTK_CFLAGS... -DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12
checking GTK_LIBS... -L/usr/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lm -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0
checking for "gthread-2.0"... yes
checking GTHREAD_CFLAGS... -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
checking GTHREAD_LIBS... -L/usr/lib64 -pthread -lgthread-2.0 -lglib-2.0
checking xine.h usability... yes
checking xine.h presence... yes
checking for xine.h... yes
checking for xine_init in -lxine... yes
checking ffmpeg/avcodec.h usability... yes
checking ffmpeg/avcodec.h presence... yes
checking for ffmpeg/avcodec.h... yes
checking for avcodec_decode_video in -lavcodec... yes
checking for av_open_input_file in -lavformat... yes
checking libraw1394/raw1394.h usability... yes
checking libraw1394/raw1394.h presence... yes
checking for libraw1394/raw1394.h... yes
checking for raw1394_new_handle in -lraw1394... yes
checking libdc1394/dc1394_control.h usability... yes
checking libdc1394/dc1394_control.h presence... yes
checking for libdc1394/dc1394_control.h... yes
checking for dc1394_camera_on in -ldc1394_control... yes
checking linux/videodev.h usability... yes
checking linux/videodev.h presence... yes
checking for linux/videodev.h... yes
checking for linux/videodev2.h... yes
checking jpeglib.h usability... yes
checking jpeglib.h presence... yes
checking for jpeglib.h... yes
checking for jpeg_destroy_decompress in -ljpeg... yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking for gzopen in -lz... yes
checking png.h usability... yes
checking png.h presence... yes
checking for png.h... yes
checking libpng/png.h usability... yes
checking libpng/png.h presence... yes
checking for libpng/png.h... yes
checking for png_read_image in -lpng12... yes
checking for png_get_valid... yes
checking for png_set_tRNS_to_alpha... yes
checking tiff.h usability... yes
checking tiff.h presence... yes
checking for tiff.h... yes
checking for TIFFReadRGBAStrip in -ltiff... yes
checking jasper/jasper.h usability... yes
checking jasper/jasper.h presence... yes
checking for jasper/jasper.h... yes
checking for jas_image_readcmpt in -ljasper... yes
checking ImfCRgbaFile.h usability... no
checking ImfCRgbaFile.h presence... no
checking for ImfCRgbaFile.h... no
configure: Checking for necessary tools to build python wrappers
checking for python... /usr/bin/python
checking for python version... 2.5
checking for python platform... linux2
checking for python script directory... ${prefix}/lib64/python2.5/site-packages
checking for python extension module directory... ${exec_prefix}/lib64/python2.5/site-packages
configure: PYTHON_CSPEC=-fPIC -I/usr/include/python2.5
configure: PYTHON_LSPEC= -L/usr/lib64/python2.5/config -lm -lpthread -ldl -lutil -lpython2.5 -Xlinker -export-dynamic
checking Python.h usability... yes
checking Python.h presence... yes
checking for Python.h... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating opencv.pc
config.status: creating opencv.spec
config.status: creating docs/Makefile
config.status: creating data/Makefile
config.status: creating cxcore/Makefile
config.status: creating cxcore/include/Makefile
config.status: creating cxcore/src/Makefile
config.status: creating cv/Makefile
config.status: creating cv/include/Makefile
config.status: creating cv/src/Makefile
config.status: creating cvaux/Makefile
config.status: creating cvaux/include/Makefile
config.status: creating cvaux/src/Makefile
config.status: creating ml/Makefile
config.status: creating ml/include/Makefile
config.status: creating ml/src/Makefile
config.status: creating otherlibs/Makefile
config.status: creating otherlibs/highgui/Makefile
config.status: creating apps/Makefile
config.status: creating apps/haartraining/Makefile
config.status: creating apps/haartraining/include/Makefile
config.status: creating apps/haartraining/src/Makefile
config.status: creating interfaces/Makefile
config.status: creating interfaces/swig/Makefile
config.status: creating interfaces/swig/filtered/Makefile
config.status: creating interfaces/swig/general/Makefile
config.status: creating interfaces/swig/python/Makefile
config.status: creating tests/Makefile
config.status: creating tests/python/Makefile
config.status: creating tests/cv/Makefile
config.status: creating tests/cv/src/Makefile
config.status: creating tests/cxts/Makefile
config.status: creating tests/cxcore/Makefile
config.status: creating tests/cxcore/src/Makefile
config.status: creating utils/Makefile
config.status: creating samples/Makefile
config.status: creating samples/c/Makefile
config.status: creating samples/python/Makefile
config.status: creating cvconfig.h
config.status: cvconfig.h is unchanged
config.status: executing depfiles commands

General configuration ================================================
Compiler: g++
CXXFLAGS: -Wall -fno-rtti -pipe -O3 -fomit-frame-pointer

Install path: /usr/local

HighGUI configuration ================================================

Windowing system --------------
Use Carbon / Mac OS X: no
Use gtk+ 2.x: yes
Use gthread: yes

Image I/O ---------------------
Use libjpeg: yes
Use zlib: yes
Use libpng: yes
Use libtiff: yes
Use libjasper: yes
Use libIlmImf: no

Video I/O ---------------------
Use QuickTime / Mac OS X: no
Use xine: yes
Use ffmpeg: yes
Use dc1394 & raw1394: yes
Use v4l: yes
Use v4l2: yes

Wrappers for other languages =========================================
Python yes

Additional build settings ============================================
Build demo apps yes

Now run make ...

ATTENTION: highgui will be built with xine support,
thus it will be a subject to GNU Public License

Fourth and next ..., if there are no errors, then
$ make
# make install
Make sure you have root privilege to run make install.

No comments: