【嵌入式编程】如何在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 格式的图像文件和位图的字节数组。
它的开源项目介绍页面,zint barcode generator download | sourceforge.net 可自行阅读。
二、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源码;
zint barcode generator - browse /zint/2.4.3 at sourceforge.net
笔者下载的版本是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生成二维码,敬请关注。

浪潮基于存储即平台战略推出新一代G6存储
Hi4315H智芯 PWM/模拟调光LED恒流驱动器5-60V电压范围降压BUCK大功率调光
导热泥会出现硬化、粉化吗?它的寿命如何呢?
远程医疗转向AI技术,虚拟医疗服务将成为现实
行动元化繁为简,助力晶圆搬运机器人性能升级
【嵌入式编程】如何在Linux平台安装zint开源库
MIMO:商机无限的无线宽带通讯新技术
友达光电宣布收购Field Emission Technol
瑞萨推64位RISC-V CPU内核MPU 华大发布智能安防安全SE芯片产品
豆瓣的十四年 靠什么坚持着
变频器输出电抗器的功能和特点是怎样的
海泰方圆提出电子文件管理“4A”模型, 强调电子文件管理的重要意义
无线传感器网络路由协议的研究与改进
恩智浦集成可调光市电LED驱动器解决方案介绍
自制水族灯diy图解
惠海半导体中低压场效率管(MOSFET)的应用领域
覆铜板涨价 PCB企业的盈利负重
如何使用NFC手机和标签让日常活动自动化
人脸识别争议不断,个人信息安全何去何从
什么是DWDM技术,它的作用是怎样的