如何在 Visual Studio 2017 中使用 zlib 库?

问题描述:

我想在我的 C++ 项目中使用 zlib 库.所以,我已经下载了 zlib 库(zlib_1_2_8_msvc2015_64.zip).然后,我在 "C:\Program Files\Zlib" 下创建了 zlib 文件夹.然后,将 zlib_1_2_8_msvc2015_64.zip 文件解压到 "C:\Program Files\Zlib" 中.

I want to use the zlib library in my c++ project. So, I have downloaded zlib library(zlib_1_2_8_msvc2015_64.zip). Then, I have created zlib folder under "C:\Program Files\Zlib". Then, Extract zlib_1_2_8_msvc2015_64.zip file into "C:\Program Files\Zlib".

之后,我打开了visual studio 2017,然后转到property => C/C++ => generalstrong> => 额外的包含目录和添加了该路径:"C:\Program Files\Zlib\msvc2015_64".

After that, I have opened visual studio 2017 and goes to property => C/C++ => general => additional include directories and added that path : "C:\Program Files\Zlib\msvc2015_64".

之后,我在我的项目中添加了 #include 头文件.但是,不起作用.

After that, I have added #include <zlib.h> header file in my project. but, not working.

那么,如何在 Visual Studio 2017 中使用 zlib 库?

So, How to use zlib library in visual studio 2017?

对于静态库安装,在链接器附加库和目录中包含 zlibstatic.lib 和目录.对于动态库,在链接器中包含 zlib.lib 并将 zlib.dll 复制到项目输出目录.

For static library installation , include the zlibstatic.lib and directories in the linker additional libraries and directories. For dynamic library , include the zlib.lib in the linker and copy the zlib.dll to the project output directory.

另一种选择是安装 vcpkg(MS 打包程序以安装基于 Windows 的开源项目)并使用 powershell 命令,例如 .\vcpkg install zlib:x64-windows-static.zlib 可以使用 .\vcpkg 集成安装

Another option is to install vcpkg ( MS packager to install windows based open source projects) and use powershell command like so .\vcpkg install zlib:x64-windows-static. The zlib can be auto integrated to your project using .\vcpkg integrate install