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
libzip with Visual Studio 2010
提问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 解决方案:
If you've not already done so, install CMake
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
Download and extract libzipto e.g.
C:\devel
In a VS10 command prompt,
cd C:\devel\zlib-1.2.7
mkdir build && cd build
cmake .. -G"Visual Studio 10" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib"
This sets the install path toC:\devel\installed\zlib
rather than the defaultC:\Program Files\zlib
. For 64-bit Windows, use"Visual Studio 10 Win64"
as the-G
parameter.msbuild /P:Configuration=Debug INSTALL.vcxproj
msbuild /P:Configuration=Release INSTALL.vcxproj
cd C:\devel\libzip-0.10.1
mkdir build && cd build
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-G
parameter.
如果您还没有这样做,请安装CMake
下载并解压zlib到例如
C:\devel
. 下载链接位于主页的一半左右。目前这提供了 zlib 版本 1.2.7。下载并解压libzip到例如
C:\devel
在VS10 命令提示符下,
cd C:\devel\zlib-1.2.7
mkdir build && cd build
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
参数。msbuild /P:Configuration=Debug INSTALL.vcxproj
msbuild /P:Configuration=Release INSTALL.vcxproj
cd C:\devel\libzip-0.10.1
mkdir build && cd build
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 snprintf
calls 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.c
patched 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 Dependencies
for the Debug configuration to change zlibwapi.lib
to zlibwapid.lib
.
我在加载时出错,因为其中一个配置在我的机器上无效,但是重新编译解决了这个问题。我还必须更改项目属性>,Configuration Properties>Linker>Input>Additional Dependencies
以便将调试配置更改zlibwapi.lib
为zlibwapid.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 文件所在的位置)。