vc2010 编译 qrencode

来源:互联网 发布:买家怎么修改淘宝评价 编辑:程序博客网 时间:2024/05/22 13:35

qrencode 是一个生成QR 二维码的开源库,用法很简单,但是没有提供在vs 系统下编译的项目文件,所以在win下使用不太方便。为此,我研究了一下,搞定了用 VC 2010 编译生成静态库的方法。

 

建立一个 win32 项目,选择生成静态库,不使用预编译头。

将 qrencode 的源文件(.c 和 .h)全部拷到vc 的项目目录中,除了 qrenc.c 。

 

编译 qrencode 时还需要有个 config.h 文件,这个文件是 configure 时自动生成的,可以用我下面提供的这个。

 

/* 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 3/* Micro version number */#define MICRO_VERSION 4/* Minor version number */#define MINOR_VERSION 4/* 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 3.4.4"/* 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 "3.4.4"/* Define to 1 if you have the ANSI C header files. */#define STDC_HEADERS 1/* Version number of package */#define VERSION "3.4.4"#define inline/* Define to 'static' if no test programs will be compiled. */#define __STATIC static/* #undef WITH_TESTS */   


然后在项目属性中添加预处理定义:HAVE_CONFIG_H

 

这里有一点需要解释一下,config.h 中有一行:

#define inline

 

之所以要这么写是因为rscode.c 文件中有个modnn的定义如下:

 

static inline int modnn(RS *rs, int x){while (x >= rs->nn) {x -= rs->nn;x = (x >> rs->mm) + (x & rs->nn);}return x;}

 

这个代码在vc2010中无法编译通过,去掉 inline 就可以顺利编译通过了。

所以才要写:

#define inline


然后编译就可以生成 qrencode.lib 了。


这里补充说明几点:

qrencode 本身是不依赖于 libpng 库的。所以不存在什么缺少 png.h 的问题。按照本文介绍的方法按部就班的做就能生成静态库,不存在任何问题。

编译时一定要排除 qrenc.c 这个文件。这个文件是 qrencode 的一个使用例子,与这个库本身无关。

缺少 png.h 或者 缺少 getopt.h 都是在编译 qrenc.c 时才会遇到的问题。与编译 qrencode 无关。如果真的需要编译 qrenc.c,那就先编译 libpng , getopt.h  不是C 标准的头文件,vs 里是没有的,但是网上也可以找到解决办法,随便百度一下就能找到。

1 0
原创粉丝点击