How can I compile libzip for Visual Studio 2010?
8 Answers
Edit:
Before starting on the answer provided here, it appears that this may no longer be an issue going by @Thomas Klausner's answer below.
The following should get you a VS10 solution:
If you've not already done so, install CMake
Download and extract zlib to 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 bug which 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 libzip to 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.
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
).
-
1When I attempt to call step 11, it will run for a while, then I will get the error Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.6") . How can I prevent this? – judeclarke May 09 '12 at 21:42
-
If the path you installed zlib to has spaces in its name, you'll need to put it in quotes: `-DCMAKE_PREFIX_PATH="C:\devel\installed\zlib"`. Also check that the path you defined in `CMAKE_INSTALL_PREFIX` when running CMake for zlib is identical to the path defined for libzip's `CMAKE_PREFIX_PATH`. – Fraser May 09 '12 at 21:50
-
I do not have spaces in the file path and I am using the exact same paths as you provided in the post, exactly. When I run step 11 I will get "-- Found ZLIB: C:/devel/installed/zlib/lib/zlib.lib (found version "1.2.6") | -- Looking for ZEXPORT | -- Looking for ZEXPORT - not found. |CMake Error at CMakeLists.txt:70 (MESSAGE): | -- ZLIB version too old, please install at least v1.1.2" (| being new lines. I have zlib version 1.2.6. – judeclarke May 09 '12 at 22:33
-
OK. Do you have zlib.h and zconf.h in `C:\devel\installed\zlib\include`? CMake's checking that the preprocessor definition ZEXPORT is available if a project `#include`s zlib.h, so if those files exist it should work. If those files don't exist, something went wrong with steps 7 & 8. If that's the case, you could open `C:\devel\zlib-1.2.7\build\zlib.sln` in Visual Studio 10 and try building the project called "INSTALL". This should also build and install zlib in one go, but the output may be more noticeable if it fails here. You'll have to do this for Debug and Release. – Fraser May 09 '12 at 22:58
-
I do have zlib.h and zconf.h in `C:\devel\installed\zlib\include`, however, I noticed that step 7 and 8 were failing. To fix this I had to go into the projects and adjust their include folders. They were including `C:/devel/zlib-1.2.6/build` instead of `C:/devel/zlib-1.2.6/`. Once I changed the include path to use `C:/devel/zlib-1.2.6/`, zlib compiled fine. It looks as if all the files I need are in `C:\devel\installed\zlib` and the zconf and zlib headers both seem to be the real file. – judeclarke May 09 '12 at 23:14
-
Ahh... I just noticed that you have zlib 1.2.6 while I have zlib 1.2.7. I hope that's the critical difference! I'll update the link to zlib in the answer. I gave the sourceforge link cause I thought it was clearer compared to zlib's own link. I guess if you delete C:\devel\installed and C:\devel\zlib-1.2.6 and go again with 1.2.7 it should be OK. – Fraser May 09 '12 at 23:23
-
It looks like steps 1 to 11 all worked once I used 1.2.7 instead of 1.2.6, however, as you mentioned there was issues when I went to compile. There were three types of issues. 1) Missing `getopt.h` in tryopen. 2) Missing `strcasecmp` in `zipcmp`. 3) Multiple projects with `unresolved external symbol _snprintf referenced in function _main`. (Potential fixes in next comment). – judeclarke May 09 '12 at 23:59
-
1) I am not sure how to fix this as this project is in a different location. I tried to add the additional include path of `C:\devel\libzip-0.10.1\src`, however, that jut results in even more linker errors. 2) Fixed by having `#define strcasecmp _stricmp` at the top of zipcmp.c. 3) Fixed using your suggestion at the bottom of the post. So basically, I fixed all my errors except for 1. – judeclarke May 10 '12 at 00:00
-
This may help with your final problem: http://stackoverflow.com/questions/10404448/getopt-h-compiling-unix-c-code-in-windows – Fraser May 10 '12 at 00:19
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.

- 47
- 1
-
1libzip does *not* compile out of the box on Windows. There's neither a project for Visual Studio nor certain necessary header files (including config.h, zlib.h, zipconf.h). Currently it's a nightmare to compile it (and no, I don't want to add cmake to my tools box). – Mike Lischke Feb 06 '14 at 10:00
-
@MikeLischke: I was reluctant for quite a while as well, but CMake seems to be the de facto standard for quite some time now, and it's used by a lot of libraries, so you might as well give in. It's not exactly fun to configure, if some additional manual configuration is needed, but sometimes it actually manages to "just work" out of the box, and produces usable VS project files. – Christian Severin Dec 11 '15 at 12:13
-
1As of this comment, zlib's MSVC* projects compiled for me out of the box – Ed S. Jun 28 '17 at 17:26
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.

- 109
- 1
- 6
Using libzip-1.0.1, zlib-1.2.8, and VS Community 2013.
Added to path:
C:\Program Files (x86)\CMake\bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319
The cmake line became:
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:
mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
to:
mask = umask(_S_IREAD | _S_IWRITE);

- 31
- 2
-
1The correct fix for the umask issue is actually this upstream commit http://hg.nih.at/libzip/rev/80457805a1e7 which will let it work cross platform. – josch Aug 08 '15 at 04:50
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 ,
the process for building zlib and libzip becomes this:
Building 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
> 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...)

- 1
- 1

- 1,793
- 19
- 38
-
:-) out of the box? You list 2 steps that must be done first (not counting to set up cmake and other preparations of the system). That's not what I understand by "out of the box". The entire cmake step is totally superfluous from a VS standpoint. It's only there to make the job of the writer easier, nothing else. And that's the wrong approach, as the saying says: "the burden should be on the writer, not the reader". But anyway, in the meantime I managed to get it working nicely and the latest improvements of libzip on Windows are just amazing. Kudos to Thomas and his team! – Mike Lischke Dec 11 '15 at 13:11
-
@MikeLischke: While it is indeed simple to "point-and-click onto the Visual Studio Solution file for your version of Visual Studio", you'd then have to edit the project to set the correct paths for the zlib dependencies, and maybe set other things that can be comfortably configured through CMake. So you save yourself the work of climbing through the VS project properties, and you save the library writers the work of constructing and debugging and updating all the project and solution files for Visual Studio 6, 2005, 2008, 2010, 2012, 2013, 2015, ... – Christian Severin Dec 14 '15 at 09:31
In current zlib version, there is a contrib for this:
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
.

- 2,286
- 22
- 51
In Visual Studio 2015, Win64:
If building libzip failing with a message like this:
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).

- 2,064
- 19
- 35
The answer given by Christian Severin helped me a lot, but needed some updates for VS2019 and 32-bit:
- When building with VS 2019, you must use the -A option, not use "Win64".
- When building with VS 2019, the 32-bit archive is "Win32", not x86.
- The "Building zlib" section has a typo, it must be
Win64" -DCMAKE_...
, with a space before the dash
Here is a working example with VS2019 and 32-bit build:
cd /d %ZLIB_DIR% && md build & cd build
cmake .. -G"Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%" -AWin32
msbuild /P:Configuration=Release INSTALL.vcxproj
cd /d %LIBZIP_DIR% && md build & cd build
cmake .. -G"Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%" -AWin32
msbuild /P:Configuration=Release ALL_BUILD.vcxproj

- 61
- 5