对zlib使用vs2019编译,没有在预处理器中加前缀命令,导致编译出来的zlib.dll 与项目之前使用的函数名不一致,运行报错。
报错信息:无法在DLL“libz64”中找到名为“Z_inflateEnd”的入口点。
在z.conf 中有以下注释:
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
* Even better than compiling with -DZ_PREFIX would be to use configure to set
* this permanently in zconf.h using "./configure --zprefix".
*/
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
/* all linked symbols */
# define _dist_code z__dist_code
# define _length_code z__length_code
…………以下省略…………
这是种表明,如果要在函数库中加前缀需要使用 Z_PREFIX ,奈何对vs编译c++程序不了解,不知道这个命令该加在哪里,根据z.conf 的代码看到应该就是因为这个命令导致没有加上前缀: #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
最后找到问题解决方案:使用vs2019编译时需要在项目属性-->c/c++-->预处理器-->预处理定义中增加Z_PREFIX;注:编译win32版本zlib需要example、minigzip属性中也加Z_PREFIX 预处理器定义