C++ 带有 Visual Studio 2010 的 libzip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10507893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:09:27  来源:igfitidea点击:

libzip with Visual Studio 2010

c++

提问by judeclarke

Is there anyway documentation for compiling libzip for Visual Studio 2010? Everything I have seen from the libzip website and Google has returned no results.

是否有为 Visual Studio 2010 编译 libzip 的文档?我从 libzip 网站和 Google 看到的一切都没有返回任何结果。

回答by Fraser

Edit:

编辑:

Before starting on the answer provided here, it appears that this may no longer be an issue going by @Thomas Klausner's answerbelow.

在开始这里提供的答案之前,似乎这可能不再是@Thomas Klausner 在下面的回答问题



The following should get you a VS10 solution:

以下应该为您提供 VS10 解决方案:

  1. If you've not already done so, install CMake

  2. Download and extract zlibto e.g. C:\devel. The download links are about halfway down the homepage. Currently this provides zlib version 1.2.7.

    • To work around this CMake bugwhich affects 64-bit Windows only, add

      if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MSVC)
        set_target_properties(zlibstatic PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
      endif()
      

      to the end of C:\devel\zlib-1.2.7\CMakeLists.txt

  3. Download and extract libzipto e.g. C:\devel

  4. In a VS10 command prompt, cd C:\devel\zlib-1.2.7

  5. mkdir build && cd build

  6. cmake .. -G"Visual Studio 10" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib"This sets the install path to C:\devel\installed\zlibrather than the default C:\Program Files\zlib. For 64-bit Windows, use "Visual Studio 10 Win64"as the -Gparameter.

  7. msbuild /P:Configuration=Debug INSTALL.vcxproj

  8. msbuild /P:Configuration=Release INSTALL.vcxproj

  9. cd C:\devel\libzip-0.10.1

  10. mkdir build && cd build

  11. cmake .. -G"Visual Studio 10" -DCMAKE_PREFIX_PATH="C:\devel\installed\zlib"Set the path to wherever you installed zlib so that CMake can find zlib's include files and libs. Again, for 64-bit Windows, use "Visual Studio 10 Win64"as the -Gparameter.

  1. 如果您还没有这样做,请安装CMake

  2. 下载并解压zlib到例如C:\devel. 下载链接位于主页的一半左右。目前这提供了 zlib 版本 1.2.7。

    • 要解决仅影响 64 位 Windows 的CMake 错误,请添加

      if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MSVC)
        set_target_properties(zlibstatic PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
      endif()
      

      到 C:\devel\zlib-1.2.7\CMakeLists.txt 的末尾

  3. 下载并解压libzip到例如C:\devel

  4. VS10 命令提示符下cd C:\devel\zlib-1.2.7

  5. mkdir build && cd build

  6. cmake .. -G"Visual Studio 10" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib"这将安装路径设置为C:\devel\installed\zlib而不是默认的C:\Program Files\zlib. 对于 64 位 Windows,"Visual Studio 10 Win64"用作-G参数。

  7. msbuild /P:Configuration=Debug INSTALL.vcxproj

  8. msbuild /P:Configuration=Release INSTALL.vcxproj

  9. cd C:\devel\libzip-0.10.1

  10. mkdir build && cd build

  11. cmake .. -G"Visual Studio 10" -DCMAKE_PREFIX_PATH="C:\devel\installed\zlib"将路径设置为安装 zlib 的位置,以便 CMake 可以找到 zlib 的包含文件和库。同样,对于 64 位 Windows,"Visual Studio 10 Win64"用作-G参数。

This should result in C:\devel\libzip-0.10.1\build\libzip.sln. It looks like there are a few POSIX-specific problems in the code, but they should hopefully be fairly easy to resolve (e.g. in zipconf.h #include <inttypes.h>needs replaced with #include <stdint.h>; there are some snprintfcalls needing replaced e.g. with _snprintf).

这应该导致C:\devel\libzip-0.10.1\build\libzip.sln. 代码中似乎有一些 POSIX 特定的问题,但希望它们应该很容易解决(例如,在 zipconf.h 中#include <inttypes.h>需要替换为#include <stdint.h>;有一些snprintf调用需要替换为,例如替换为_snprintf)。

回答by Thomas Klausner

I can't comment, so just in addition to Fraser's answer: In the last days, libzip's latest repository version should compile on VS without additional patches. Please try it out and let the developers know if parts are still missing.

我无法发表评论,所以除了 Fraser 的回答之外:在过去的日子里,libzip 的最新存储库版本应该可以在 VS 上编译,而无需额外的补丁。请尝试一下,如果部件仍然缺失,请告知开发人员。

回答by Murasaki

Can't comment on answer above but was trying to get this to work and in the end found that the Output directory under the configuration properties and the comand in debugging.

无法对上面的答案发表评论,但试图让它发挥作用,最后发现配置属性下的输出目录和调试中的命令。

You can remove ALL_BUILD, ZERO_CHECK, INSTALL and PACKAGE and it will build fine without any of the linking errors or linux specific errors.

您可以删除 ALL_BUILD、ZERO_CHECK、INSTALL 和 PACKAGE,它可以正常构建而不会出现任何链接错误或 linux 特定错误。

回答by Robert

Using libzip-1.0.1, zlib-1.2.8, and VS Community 2013.

使用 libzip-1.0.1、zlib-1.2.8 和 VS Community 2013。

Added to path:

添加到路径:

C:\Program Files (x86)\CMake\bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319

C:\Program Files (x86)\CMake\bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319

The cmake line became:

cmake 行变为:

cmake .. -G"Visual Studio 12 Win64" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib"

devel\libzip-1.0.1\lib\zip_source_filep.c:189 changed:

devel\libzip-1.0.1\lib\zip_source_filep.c:189 更改:

mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);

to:

到:

mask = umask(_S_IREAD | _S_IWRITE);

回答by Christian Severin

Using

使用

  • an environment variable %ZLIB_DIR%for the path to zlib-1.2.8,
  • %LIBZIP_DIR%for the path to libzip-1.0.1
  • VS 2015 Express Edition, and
  • the file %LIBZIP_DIR%/lib/zip_source_filep.cpatched according to http://hg.nih.at/libzip/rev/80457805a1e7,
  • %ZLIB_DIR%zlib-1.2.8 路径的环境变量,
  • %LIBZIP_DIR%对于 libzip-1.0.1 的路径
  • VS 2015 速成版,以及
  • %LIBZIP_DIR%/lib/zip_source_filep.c根据http://hg.nih.at/libzip/rev/80457805a1e7修补的文件,

the process for building zlib and libzip becomes this:

构建 zlib 和 libzip 的过程变成了这样:



Building zlib

构建 zlib

> cd /d %ZLIB_DIR% && md build & cd build
> cmake .. -G"Visual Studio 14 2015 Win64"- DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%"
> msbuild /P:Configuration=Debug INSTALL.vcxproj
> msbuild /P:Configuration=Release INSTALL.vcxproj



Building libzip

构建 libzip

> cd /d %LIBZIP_DIR% && md build & cd build
> cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH="%ZLIB_DIR%"
> msbuild /P:Configuration=Debug ALL_BUILD.vcxproj
> msbuild /P:Configuration=Release ALL_BUILD.vcxproj


Done!


完毕!

(So you see, @MikeLischke, CMake does indeed work out-of-the-box sometimes...)

(所以你看,@MikeLischke,CMake 有时确实开箱即用......)

回答by Denise Skidmore

In current zlib version, there is a contrib for this:

在当前的 zlib 版本中,有一个贡献:

zlib-1.2.8\contrib\vstudio\vc10\zlibvc.sln

zlib-1.2.8\contrib\vstudio\vc10\zlibvc.sln

I got an error on load because one of the configurations wasn't valid on my machine, but a recompile took care of that. I also had to change the project properties>Configuration Properties>Linker>Input>Additional Dependenciesfor the Debug configuration to change zlibwapi.libto zlibwapid.lib.

我在加载时出错,因为其中一个配置在我的机器上无效,但是重新编译解决了这个问题。我还必须更改项目属性>,Configuration Properties>Linker>Input>Additional Dependencies以便将调试配置更改zlibwapi.libzlibwapid.lib.

回答by Dess

In Visual Studio 2015, Win64:

在 Visual Studio 2015 中,Win64:

If building libzip failing with a message like this:

如果构建 libzip 失败并显示如下消息:

Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.8").

All you have to do is copy the generated 'zlib.dll/zlibd.zll' and 'zlib.lib/zlibd.lib' to the top of the zlib directory (where the .h/.c files are).

您所要做的就是将生成的“zlib.dll/zlibd.zll”和“zlib.lib/zlibd.lib”复制到 zlib 目录的顶部(.h/.c 文件所在的位置)。