qrencode 第三方库 的vs编译---------------------完全正确

http://blog.csdn.net/liyuanbhu/article/details/44647139



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

 

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

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

 

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

 

  1. /* config.h.  Generated from config.h.in by configure.  */  
  2. /* config.h.in.  Generated from configure.ac by autoheader.  */  
  3.   
  4. /* Define to 1 if you have the <inttypes.h> header file. */  
  5. #define HAVE_INTTYPES_H 1  
  6.   
  7. /* Define to 1 if using pthread is enabled. */  
  8. #undef HAVE_LIBPTHREAD  
  9.   
  10. /* Define to 1 if you have the <memory.h> header file. */  
  11. #define HAVE_MEMORY_H 1  
  12.   
  13. /* Define to 1 if you have the <stdint.h> header file. */  
  14. #define HAVE_STDINT_H 1  
  15.   
  16. /* Define to 1 if you have the <stdlib.h> header file. */  
  17. #define HAVE_STDLIB_H 1  
  18.   
  19. /* Define to 1 if you have the <strings.h> header file. */  
  20. #define HAVE_STRINGS_H 1  
  21.   
  22. /* Define to 1 if you have the <string.h> header file. */  
  23. #define HAVE_STRING_H 1  
  24.   
  25. /* Define to 1 if you have the `strdup' function. */  
  26. #define HAVE_STRDUP 1  
  27.   
  28. /* Define to 1 if you have the <sys/stat.h> header file. */  
  29. #define HAVE_SYS_STAT_H 1  
  30.   
  31. /* Define to 1 if you have the <sys/types.h> header file. */  
  32. #define HAVE_SYS_TYPES_H 1  
  33.   
  34. /* Define to 1 if you have the <unistd.h> header file. */  
  35. #define HAVE_UNISTD_H 1  
  36.   
  37.   
  38. /* Major version number */  
  39. #define MAJOR_VERSION 3  
  40.   
  41. /* Micro version number */  
  42. #define MICRO_VERSION 4  
  43.   
  44. /* Minor version number */  
  45. #define MINOR_VERSION 4  
  46.   
  47. /* Name of package */  
  48. #define PACKAGE "qrencode"  
  49.   
  50. /* Define to the address where bug reports for this package should be sent. */  
  51. #define PACKAGE_BUGREPORT ""  
  52.   
  53. /* Define to the full name of this package. */  
  54. #define PACKAGE_NAME "QRencode"  
  55.   
  56. /* Define to the full name and version of this package. */  
  57. #define PACKAGE_STRING "QRencode 3.4.4"  
  58.   
  59. /* Define to the one symbol short name of this package. */  
  60. #define PACKAGE_TARNAME "qrencode"  
  61.   
  62. /* Define to the home page for this package. */  
  63. #define PACKAGE_URL ""  
  64.   
  65. /* Define to the version of this package. */  
  66. #define PACKAGE_VERSION "3.4.4"  
  67.   
  68. /* Define to 1 if you have the ANSI C header files. */  
  69. #define STDC_HEADERS 1  
  70.   
  71. /* Version number of package */  
  72. #define VERSION "3.4.4"  
  73.   
  74. #define inline  
  75.   
  76. /* Define to 'static' if no test programs will be compiled. */  
  77. #define __STATIC static  
  78. /* #undef WITH_TESTS */  
  79.      


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

 

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

#define inline

 

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

 

  1. static inline int modnn(RS *rs, int x){  
  2.     while (x >= rs->nn) {  
  3.         x -= rs->nn;  
  4.         x = (x >> rs->mm) + (x & rs->nn);  
  5.     }  
  6.     return x;  
  7. }  

 

这个代码在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 里是没有的,但是网上也可以找到解决办法,随便百度一下就能找到。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值