gnu barcode 是一个用来生成条形码的库。主页在:
gnu/software/barcode/
对这个库就不多介绍了。
因为装了 MSYS2, 本来觉得编译这个库很简单,configure, make, make install 三步就够了。结果 第二步 mingw32make 时就出了错,提示:
make allrecursive
process_begin: CreateProcess(NULL, make allrecursive, …) failed.
make (e=2): 系统找不到指定的文件。
mingw32make: *** [Makefile:1271: all] Error 2
没找到解决办法。 只能想别的办法编译了。既然 MSYS2 编译出了点问题,那就用 VS 吧。
仔细翻了翻源代码,发现只要编译几个 C 文件就行:
codabar 、code11 、 code128 、code39 、code93 、 ean、i25 、 library 、 msi 、 plessey 、pcl 、ps、svg。
cmd main 和 sample 这三个不用管。
为了编译成 Dll,还需要个 barcode.def 文件。手写了一份:
1 ; gnu barcode library 2 EXPORTS 3 ; basic functions 4 Barcode_Create 5 Barcode_Encode 6 Barcode_Position 7 Barcode_Print 8 Barcode_Encode_and_Print 9 Barcode_Version 10 11 ; advanced functions至此,准备工作就差不多了。我没用 VS 的IDE ,用了 qtcreator。 这个 IDE 比较轻量,还可以手写 .pro 文件。
下面是我们写的 barcode.pro 文件:
1 # 2 # 3 # Project created by QtCreator 20200522T21:57:07 4 # 5 # 6 7 VERSION = 0.99 8 QT = core gui 9 10 ConFIG += dll 11 TEMPLATE = lib 12 13 #DEFINES += GNUBARCODE_LIBRARY 14 # The following define makes your cpiler emit warnings if you use 15 # any feature of Qt which has been marked as deprecated (the exact warnings 16 # depend on your cpiler). Please consult the documentation of the 17 # deprecated API in order to know how to port your code away fr it. 18 DEFINES += QT_DEPRECATED_WARNINGS 19 20 # You can also make your code fail to cpile if you use deprecated APIs. 21 # In order to do so, uncment the following line. 22 # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 25 SOURCES += \ 26 codabar \ 27 code11 \ 28 code128 \ 29 code39 \ 30 code93 \ 31 ean \ 32 i25 \ 33 library \ 34 msi \ 35 plessey \ 36 pcl \ 37 ps \ 38 svg 39 40 HEADERS += \ 41 barcode.h \ 42 config.h 43 44 unix 48 49 win32 else 65 }编译时还会提示一些错误,如下:
错误 1:
barcode.h:29: error: C1083: 无法打开包括文件: “gettext.h”: No such file or directory
解决办法:去掉对 gettext.h 的包含。
/// #include// 这行注释掉
/// #define _(X) gettext (X) //改为:#define _(X) (X)
错误 2:
library:29: error: C1083: 无法打开包括文件: “unistd.h”: No such file or directory
解决办法:将 config.h 文件中 #define HAVE_UNISTD_H 1
改为:
#undef HAVE_UNISTD_H
之后就可以正常的生成 dll 和 lib 文件了。