如何在linux平台安装zint开源库

一、zint开源库的介绍

zint 是一个开源的条码编码库,它支持超过50种条码,包括 Code-128, Data Matrix, EAN-128, UPC/EAN, ITF, QR Code, Code 16k, PDF417, MicroPDF417, LOGMARS, Maxicode, GS1 DataBar, Aztec, Composite Symbols 等等,基本上你见过的条码都能用它来进行编码,它支持直接输出 PNG 格式的图像文件和位图的字节数组。

它的开源项目介绍页面,https://sourceforge.net/projects/zint/ 可自行阅读。

二、zint源码在linux平台下的编译和安装

编译平台介绍:

系统版本 :Red Hat Enterprise Linux6

Linux内核版本:Linux localhost.localdomain 2.6.32-71.el6.i686 #1 SMP Wed Sep 1 01:26:34 EDT 2010 i686 i686 i386 GNU/Linux

gcc版本 : 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) 

zint版本:zint-2.4.3

 

编译步骤:

1)         下载源码

在开源页面中下载到对应版本的zint源码;

https://sourceforge.net/projects/zint/files/zint/2.4.3/

笔者下载的版本是zint-2.4.3,对应的压缩包文件为 zint-2.4.3.tar.gz

将下载的源码放于一个新的linux的目录下,比如/zint_src

2)         解压源码

cd /zint_src

tar –xvf zint-2.4.3.tar.gz 解压到当前目录

解压完了之后,用ls看一下当前路径,如果有zint-2.4.3文件夹生成,且里面有文件,解压过程没有报错,则表示解压成功了。

3)         阅读编译指南

cd zint-2.4.3

vi readme-cmake

里面的内容如下:

how to :

mkdir build

cd build

cmake ..

make [-j nr_proc+1]

make install

4)         开始正式编译

mkdir build

cd build

cmake ..

执行后这句后,成功的话就会提示 Build files have been written to: /zint_src/zint-2.4.3/build

这个时候ls一下当前目录就会发现有makefile了,我们就可以使用make直接来安装了

make install

输入完后,会看到百分比提示了:

【笔者第一次make install报错了,是因为windows主机和linux虚拟机之间使用了共享文件,刚好做so文件软链接的时候就报错了,如下:】

[root@localhost build]# make install

Scanning dependencies of target zint

[  1%] Building C object backend/CMakeFiles/zint.dir/common.c.o

[  3%] Building C object backend/CMakeFiles/zint.dir/library.c.o

[  5%] Building C object backend/CMakeFiles/zint.dir/render.c.o

.....[中间省略]

[ 55%] Building C object backend/CMakeFiles/zint.dir/code1.c.o

[ 57%] Building C object backend/CMakeFiles/zint.dir/gridmtx.c.o

Linking C shared library libzint.so

CMake Error: cmake_symlink_library: System Error: Operation not supported

CMake Error: cmake_symlink_library: System Error: Operation not supported

make[2]: *** [backend/libzint.so.2.4.1] 错误 1

make[1]: *** [backend/CMakeFiles/zint.dir/all] 错误 2

make: *** [all] 错误 2

[root@localhost build]#

如果按照一开始将源码放于/zint_src (非主机与虚拟机的共享目录),则可以很顺利的编译和安装,如下:

root@localhost build]# make install

Scanning dependencies of target zint

[  1%] Building C object backend/CMakeFiles/zint.dir/common.c.o

[  3%] Building C object backend/CMakeFiles/zint.dir/library.c.o

[  5%] Building C object backend/CMakeFiles/zint.dir/render.c.o

[  7%] Building C object backend/CMakeFiles/zint.dir/ps.c.o

[  9%] Building C object backend/CMakeFiles/zint.dir/large.c.o

[ 11%] Building C object backend/CMakeFiles/zint.dir/reedsol.c.o

.....[中间省略]

[ 53%] Building C object backend/CMakeFiles/zint.dir/code49.c.o

[ 55%] Building C object backend/CMakeFiles/zint.dir/code1.c.o

[ 57%] Building C object backend/CMakeFiles/zint.dir/gridmtx.c.o

Linking C shared library libzint.so

[ 57%] Built target zint

Scanning dependencies of target zint_frontend

[ 59%] Building C object frontend/CMakeFiles/zint_frontend.dir/main.c.o

Linking C executable zint

[ 59%] Built target zint_frontend

Scanning dependencies of target QZint

[ 61%] Building CXX object backend_qt4/CMakeFiles/QZint.dir/qzint.cpp.o

Linking CXX shared library libQZint.so

[ 61%] Built target QZint

[ 63%] Generating qrc_resources.cxx

[ 65%] Generating moc_mainwindow.cxx

[ 67%] Generating moc_datawindow.cxx

[ 69%] Generating moc_sequencewindow.cxx

[ 71%] Generating moc_exportwindow.cxx

[ 73%] Generating ui_mainWindow.h

[ 75%] Generating ui_extData.h

[ 76%] Generating ui_extSequence.h

[ 78%] Generating ui_extExport.h

Scanning dependencies of target zint-qt

[ 80%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/barcodeitem.cpp.o

[ 82%] Building CXX object frontend_qt4/CMakeFiles/zint-qt.dir/main.cpp.o

[ 84%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/mainwindow.cpp.o

[ 86%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/datawindow.cpp.o

[ 88%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/sequencewindow.cpp.o

[ 90%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/exportwindow.cpp.o

[ 92%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/moc_mainwindow.cxx.o

[ 94%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/moc_datawindow.cxx.o

[ 96%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/moc_sequencewindow.cxx.o

[ 98%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/moc_exportwindow.cxx.o

[100%] Building CXX object

frontend_qt4/CMakeFiles/zint-qt.dir/qrc_resources.cxx.o

Linking CXX executable zint-qt

[100%] Built target zint-qt

Install the project...

-- Install configuration: "RelWithDebInfo"

-- Installing: /usr/share/cmake/Modules/FindZint.cmake

-- Installing: /usr/local/lib/libzint.so.2.4.1

-- Installing: /usr/local/lib/libzint.so.2.4

-- Installing: /usr/local/lib/libzint.so

-- Installing: /usr/local/include/zint.h

-- Installing: /usr/local/bin/zint

-- Installing: /usr/local/lib/libQZint.so.2.4.1

-- Installing: /usr/local/lib/libQZint.so.2.4

-- Installing: /usr/local/lib/libQZint.so

-- Installing: /usr/local/include/qzint.h

-- Installing: /usr/local/bin/zint-qt

到这里zint库就已经安装好了。

5)         测试zint和libzint

通过第4步后已经完成了安装,这个步骤我们来试一下zint和libzint如下:

先看下libzint是否安装成功,

[root@localhost build]# ls -al /usr/local/lib/libzint.so

lrwxrwxrwx. 1 root root 14 10月 16 17:20 /usr/local/lib/libzint.so ->

libzint.so.2.4

则正是zint动态库已经链接完成。

测试zint 如下:

在终端输入 zint –h

[liluchang@localhost src]$ zint -h

Zint version 2.4.1

Encode input data in a barcode and save as a PNG, EPS or SVG file.

 

  -h, --help            Display this message.

  -t, --types           Display table of barcode types

  -i, --input=FILE      Read data from FILE.

  -o, --output=FILE     Write image to FILE. (default is out.png)

  -d, --data=DATA       Barcode content.

  -b, --barcode=NUMBER  Number of barcode type (default is 20 (=Code128)).

  --height=NUMBER       Height of symbol in multiples of x-dimension.

  -w, --whitesp=NUMBER  Width of whitespace in multiples of x-dimension.

  --border=NUMBER       Width of border in multiples of x-dimension.

  --box                 Add a box.

  --bind                Add boundary bars.

  -r, --reverse         Reverse colours (white on black).

  --fg=COLOUR           Specify a foreground colour.

  --bg=COLOUR           Specify a background colour.

  --scale=NUMBER        Adjust size of output image.

  --directpng           Send PNG output to stdout

  --directeps           Send EPS output to stdout

  --directsvg           Send SVG output to stdout

  --dump                Dump binary data to stdout

  --rotate=NUMBER       Rotate symbol (PNG output only).

  --cols=NUMBER         (PDF417) Number of columns.

  --vers=NUMBER         (QR Code) Version

  --secure=NUMBER       (PDF417 and QR Code) Error correction level.

  --primary=STRING      (Maxicode and Composite) Structured primary message.

  --mode=NUMBER         (Maxicode and Composite) Set encoding mode.

  --gs1                 Treat input as GS1 data

  --binary              Treat input as Binary data

  --notext              Remove human readable text

  --square              Force Data Matrix symbols to be square

  --init                Create reader initialisation symbol (Code 128)

  --smalltext           Use half-size text in PNG images

  --batch               Treat each line of input as a separate data set

error: No data received, no symbol generated

[liluchang@localhost src]$

能看到版本信息,证明zint这个bin文件已经安装好了。

 

至此zint和libzint的安装已全部结束,笔者在安装的过程中,几乎使用的默认路径,感兴趣的童鞋可以试着修改一些自定义的安装路径,可以定制化自己的zint和libzint。

本章介绍到此结束,下一篇将介绍如何使用libzint生成二维码,敬请关注。

2016.10.16 Li.Recan

posted @ 2016-10-16 19:01  架构师李肯  阅读(4648)  评论(3编辑  收藏  举报