judeclarke
judeclarke

Reputation: 1116

libzip with Visual Studio 2010

How can I compile libzip for Visual Studio 2010?

Upvotes: 13

Views: 24799

Answers (8)

GersonKurz
GersonKurz

Reputation: 71

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

Upvotes: 0

Dess
Dess

Reputation: 2669

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).

Upvotes: 0

Denise Skidmore
Denise Skidmore

Reputation: 2416

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.

Upvotes: 0

Christian Severin
Christian Severin

Reputation: 1831

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...)

Upvotes: 2

Robert
Robert

Reputation: 31

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);

Upvotes: 3

Murasaki
Murasaki

Reputation: 119

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.

Upvotes: 3

Fraser
Fraser

Reputation: 78378

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:

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

  2. 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

  3. Download and extract libzip to 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\zlib rather than the default C:\Program Files\zlib. For 64-bit Windows, use "Visual Studio 10 Win64" as the -G parameter.

  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 -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).

Upvotes: 29

Thomas Klausner
Thomas Klausner

Reputation: 47

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.

Upvotes: 4

Related Questions