概述

Libqrencode是一个开源、C语言编写的二维码编码库。
Github源仓库地址

创建项目

打开VS2019,创建一个C++静态库项目。

添加文件

解压Libqrencode的源代码文件后,将以下.h文件和.c文件添加到VS项目中:
bitstream.h/bitstream.c
framework.h
mask.h/mask.c
mmask.h/mmask.c
mqrspec.h/mqrspec.c
qrencode.h/qrencode.c
qrencode_inner.h/
qrinput.h/qrinput.c
qrspec.h/qrspec.c
rsecc.h/rsecc.c
split.h/split.c

创建config.h

config.h是项目的配置文件,因为不是通过CMake来生成解决方案,需要自己手动写一下,内容其实就是源文件config.h.in中的内容。
config.h文件内容如下:

/* config.h.  Generated from config.h.in by configure.  */
/* config.h.in.  Generated from configure.ac by autoheader.  */
 
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
 
/* Define to 1 if using pthread is enabled. */
#undef HAVE_LIBPTHREAD
 
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
 
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
 
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
 
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
 
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
 
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
 
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
 
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
 
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
 
 
/* Major version number */
#define MAJOR_VERSION 4
 
/* Micro version number */
#define MICRO_VERSION 1
 
/* Minor version number */
#define MINOR_VERSION 1
 
/* Name of package */
#define PACKAGE "qrencode"
 
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
 
/* Define to the full name of this package. */
#define PACKAGE_NAME "QRencode"
 
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "QRencode 4.1.1"
 
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "qrencode"
 
/* Define to the home page for this package. */
#define PACKAGE_URL ""
 
/* Define to the version of this package. */
#define PACKAGE_VERSION "4.1.1"
 
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
 
/* Version number of package */
#define VERSION "4.1.1"
 
#define inline
 
/* Define to 'static' if no test programs will be compiled. */
#define __STATIC static
/* #undef WITH_TESTS */

需要修改的就是包含VERSION字段的宏定义,因为我编译的库是4.1.1,上面的内容就改为了4.1.1。改好之后,将头文件添加到VS项目中就可以了。

配置预处理器定义

打开VS项目的属性页,依序点击C/C++->预处理器,在预处理器定义的最后添加一个宏“HAVE_CONFIG_H”。

编译项目

进行到这一步,就可以生成项目了,项目生成后,会生成一个“$(ProjectName).lib”的静态库。将这个静态库和项目中的头文件“qrencode.h”放到其它项目中,就可以直接使用了。

最后修改:2023 年 08 月 04 日
如果觉得我的文章对你有用,请随意赞赏