Clone and build ZBar on Ubuntu and Mac OS X

ZBar is a very fast open source bar codes reader library.

I just compare it with ZXing during a week, finally choose ZBar.

For me, zbarcam(video4linux required), zbarimg(ImageMagick reurired), Qt(Qt4 required) and GTK+/PyGTK(GTK+-2.x required) is useless.

Because I will use ZBar on iOS or Android devices, the above features will NOT be supported in my build phases.


hg clone
cd zbar

Let's do some check

ant-Thinkpad-R60:zbar ant $ hg summary
parent: 362:38e78368283d tip
Added tag iPhoneSDK-1.3.1 for changeset 5eb3c8786845
branch: default
commit: 320 unknown (clean)
update: (current)

Make sure you have read HACKING file before build, autoconf automake libtool gettext and pkg-config needed.

autoreconf -if

Build android example

Clone fixed libiconv, which support android cross-compile:

First, we will build the andorid sdk

cd android



Make sure you are using JDK1.6. It seems that android sdk has bugs when using JDK1.7

ant-Thinkpad-R60:android ant $ locate javac|grep bin

ant clean
ant zbar-all

Second, try the example

cd examples/CameraTest/

Copy the sdk libs, build and install the apk

ant-Thinkpad-R60:CameraTest ant $ cp ../../libs ./ -r
ant-Thinkpad-R60:CameraTest ant $ tree libs
├── armeabi
│   ├──
│   └──
├── armeabi-v7a
│   ├──
│   └──
├── x86
│   ├──
│   └──
└── zbar.jar

ant debug
ant installd

Enjoy ZBar scanning.

Troubleshoots on Ubuntu

If you are using JDK1.7 to build zbar.jar but not JDK1.6

ant-Thinkpad-R60:CameraTest ant $ javac -version
javac 1.7.0_21

you will in troubles when dex converting zbar.jar which include Config.class, Image.class, ImageScanner.class etc.

[dx] bad class file magic (cafebabe) or version (0033.0000)

Switch JDK1.6 will fix it.

Mac OS X

brew install developer tools: autoconf automake libtool pkg-config gettext


YantongtekiMacBook-Pro:mdblog ant [master] $ brew info gettext
gettext: stable 0.18.2 (bottled)

This formula is keg-only.
OS X provides the BSD gettext library and some software gets confused if both are in the library path.

/usr/local/Cellar/gettext/ (366 files, 12M)
/usr/local/Cellar/gettext/0.18.2 (366 files, 11M)
  Poured from bottle

Because default will use OS X gettext library, you will get errors when autoreconf

YantongtekiMacBook-Pro:zbar ant $ autoreconf -fi warning: macro 'AM_ICONV' not found in library
glibtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'.
glibtoolize: copying file `config/'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIR, `config'.
glibtoolize: copying file `config/libtool.m4'
glibtoolize: copying file `config/ltoptions.m4'
glibtoolize: copying file `config/ltsugar.m4'
glibtoolize: copying file `config/ltversion.m4'
glibtoolize: copying file `config/lt~obsolete.m4' warning: macro 'AM_ICONV' not found in library error: possibly undefined macro: AM_ICONV
      If this token and others are legitimate, please use m4_pattern_allow.
            See the Autoconf documentation.
            autoreconf: /usr/local/Cellar/autoconf/2.69/bin/autoconf failed with exit status: 1

Include the brew version will fix that

autoreconf -fi -I /usr/local/Cellar/gettext/0.18.2/share/aclocal

Also patch

diff -r 38e78368283d
--- a/  Sun Oct 14 23:02:08 2012 -0700
+++ b/  Mon Jun 24 20:40:08 2013 +0800
@@ -7,6 +7,7 @@
 LT_INIT([dlopen win32-dll])
 LT_LANG([Windows Resource])


Configure ZBar

./configure --disable-video --without-imagemagick --without-gtk --without-qt

Patch android sdk

Follow the Ubuntu build phases to build the android sdk and example.