1 下载

下载Zbar源码:
http://zbar.sourceforge.net/download.html
注意 git上的源码无configure配置文件,
https://github.com/ZBar/ZBar
解压缩:

tar -jxvf zbar-0.10.tar.bz2

2 配置文件

创建输出目录

cd zbar-0.10                                                  
mkdir output

配置编译ZBar库:

./configure --help

打印帮助信息,其中配置选项如下:

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-pic              try to use only PIC/non-PIC objects [default=use
                          both]
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-gnu-ld           assume the C compiler uses GNU ld default=no
  --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
  --without-libiconv-prefix     don't search for libiconv in includedir and libdir
  --with-x                use the X Window System
  --without-xshm          disable support for X shared memory extension
  --without-xv            disable support for XVideo extension
  --without-jpeg          disable support for JPEG image conversions
  --without-imagemagick   disable support for scanning images using
                          ImageMagick
  --with-npapi            enable support for Firefox/Mozilla/OpenOffice NPAPI
                          plugin
  --without-gtk           disable support for GTK+ widget
  --without-python        disable support for Python bindings
  --without-qt            disable support for Qt4 widget

配置文件:

./configure --prefix=$PWD/output/ --without-gtk --without-qt --without-imagemagick --without-python --disable-video

打印显示:

please verify that the detected configuration matches your expectations:
------------------------------------------------------------------------
X                 --with-x=yes
pthreads          --enable-pthread=yes
v4l               --enable-video=no
        => zbarcam video scanner will *NOT* be built
jpeg              --with-jpeg=yes
Magick++          --with-imagemagick=no
        => the zbarimg file scanner will *NOT* be built
Python            --with-python=no
GTK+              --with-gtk=no
        => the GTK+ widget will *NOT* be built
Qt4               --with-qt=no
        => the Qt4 widget will *NOT* be built

3 常见错误

常见错误:可以参考一下两篇博文
https://blog.csdn.net/Visrul/article/details/80406830
https://blog.csdn.net/felix86/article/details/41443741

我的错误1:

如果,这里是说如果你后面需要配置文件出错;请参考如下:
获取相关编译支持

1. $ sudo apt-get install libqt4-dev  //qt相关
2. $ sudo apt-get install libv4l-dev
3. $ sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h  
4. $ sudo apt-get install python-gtk2-dev
5. $ sudo apt-get install imagemagick libmagickwand-dev/

比如
我想用jpeg,但是怎么配置都是no,这里我就安装对应的包即可,有点大

sudo apt-get install imagemagick libmagickwand-dev

我的错误2:编译ZBar时,./configure之后make时提示如下错误。

usr/include/x86_64-linux-gnu/bits/stdio2.h:140:1: error: expected
identifier or ‘(’ before ‘{’ token In file included from
/usr/include/stdio.h:937:0, from zbar/debug.h:60, from
zbar/scanner.c:34: /usr/include/x86_64-linux-gnu/bits/stdio2.h:140:1:
error: expected identifier or ‘(’ before ‘{’ token

解决方法:

export CFLAGS="" //将CFLAGS环境变量置为空

然后重新 ./configure ***

此时再make,则会成功。

4. 结束

在output中 生成编译的zbar库 ;

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐