libqrencode学习笔记(一): VS2015编译qrencode-3.4.4
来源:互联网 发布:mysql group by 多列 编辑:程序博客网 时间:2024/06/02 04:06
0 前言
因为无聊的时间看了一个2分钟短视频介绍了下二维码的原理,觉得还蛮有意思的。作为一个程序员,就想写写代码搞下看看。先是百度了下C/C++实现二维码,发现已经有成熟的二维码开源库,于是下载源码,按照源码中README文件中说明的Compile & install在Cygwin中操作,发现只能生成libqrencode.a静态库,没有libqrencode.lib静态库供Windows下VS编程使用。再然后,就是再搜索了下相关资料,最后,成功编译出了供Windows下VS编程使用的libqrencode.lib静态库。
1 准备
/* 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 <dlfcn.h> header file. */#define HAVE_DLFCN_H 1/* Define if you have the iconv() function and it works. *//* #undef HAVE_ICONV *//* Define to 1 if you have the <inttypes.h> header file. */#define HAVE_INTTYPES_H 1/* Define to 1 if using pthread is enabled. *///#define HAVE_LIBPTHREAD 1/* 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 `strdup' function. */#define HAVE_STRDUP 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 <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/* Define to the sub-directory in which libtool stores uninstalled libraries. */#define LT_OBJDIR ".libs/"/* 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 to empty if `const' does not conform to ANSI C. *//* #undef const *//* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */#ifndef __cplusplus/* #undef inline */#endif/* Define to 'static' if no test programs will be compiled. */#define __STATIC static/* #undef WITH_TESTS */
2 编译
1)解压qrencode-3.4.4源码后,只保留.h和.c文件,如下图只保留蓝框中的文件,红框中的删除。其中,蓝框中已经把上面准备步骤中的config.h文件加进去了,同把蓝框中有被小红框标出的qrenc.c文件删除,这个文件只是一个测试文件,打开此文件可看到其中的main函数,如果保留此测试文件,编译生成.lib静态库时会发生错误。
2)在VS中创建一个 win32 项目,选择生成静态库,不使用预编译头。将 步骤1)中操作保留qrencode 的源文件(.c 和 .h)全部拷到项目目录中。然后,选中项目,点击右键,属性 --> 配置属性 --> C/C++ --> 预处理器,在“预处理器定义”中添加HAVE_CONFIG_H。
最后,编译项目生成解决方案。
出现下面“无法打开包括文件:“pthread.h””的错误,而Pthread是由POSIX提出的一套通用的线程库,在Linux平台下,它被广泛的支持,而windows平台下,却并不被支持,所以打不到这个头文件。点击错误,打到错误所在行,可以发现有:
#ifdef HAVE_LIBPTHREAD
#include <pthread.h>
#endif
所以,这是因为定义了HAVE_LIBPTHREAD变量导致的。而这个变量的定义正是在用Cygwin模拟Linux环境自动生成的config.h文件中有:#define HAVE_LIBPTHREAD 1。故因此,把这句注释掉,再编译,将成功在Debug文件夹下生成libqrencode.lib静态库。
如果不是自己用Cygwin自动生成的config.h文件,而是直接复制我上面贴出来的config.h内容,编译会直接成功,不会出错,因为我贴出来时已经把这句定义注释了。
3 使用
使用静态库比较简单,只需要拷贝生成的libqrencode.lib和源码中的qrencode.h两个文件到你的项目中。
然后配置属性 --> C/C++ --> 常规 --> 附加包含目录,加入qrencode.h所在路径
配置属性 --> 链配置属性 --> 链接器 --> 常规 --> 附加库目录,加入libqrencode.lib所在路径
配置属性 --> 链配置属性 --> 链接器 --> 输入 --> 附加依赖项,加入libqrencode.lib
参考文献:
1. http://blog.csdn.net/liyuanbhu/article/details/44647139
- libqrencode学习笔记(一): VS2015编译qrencode-3.4.4
- C++学习笔记之QT/VS编译Qrencode
- libqrencode学习笔记(二): 用libqrencode静态库库生成二维码并保存为BMP图片
- C++(学习笔记)——VS2015静态编译libcurl
- protobuf vs2015编译 和 示例学习笔记
- 编译学习笔记(一)
- VS2010 编译生成 qrencode
- vc2010 编译 qrencode
- QRencode编译Makefile
- qrencode交叉编译
- 基于qrencode-3.4.4的二维码生成
- OpenCV学习笔记(4)VS2015配置opencv3.2.0
- libqrencode库编译及使用
- OpenCV学习笔记(一)——OpenCV3.1.0+VS2015开发环境配置
- opencv学习笔记(一)(VS2015-openCV3.1.0-win10 配置说明)
- OpenCV学习笔记(一)——OpenCV3.1.0+VS2015开发环境配置
- OpenCV学习笔记(一)——OpenCV3.1.0+VS2015开发环境配置
- 编译原理学习笔记(一)体系结构
- 用户体验总结
- 详解C#中的反射
- Java实现-删除链表中倒数第n个节点
- failed to find Build Tools revision 23.0.0 rc2 Install Build Tools 23.0.0 rc2 and sync project
- 价值感 愿景树立
- libqrencode学习笔记(一): VS2015编译qrencode-3.4.4
- 10个Java常见运行时异常
- 在java中String类为什么要设计成final?
- 学习Linux命令(45)
- MySQL性能优化(特别是最后保证随机查到数据的思想,而不是前几条)
- 哈希表的应用之电话本
- 【note】Swift初见笔记
- Java多线程中Synchronized和Lock的区别
- 【note】the swift programming language Swift教程笔记