简体   繁体   中英

libzip with Visual Studio 2010

How can I compile libzip for Visual Studio 2010?

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 eg 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 eg 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 (eg in zipconf.h #include <inttypes.h> needs replaced with #include <stdint.h> ; there are some snprintf calls needing replaced eg with _snprintf ).

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.

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.

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

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

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 .

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

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

Visual Studio 2022

mkdir build && cd build

cmake.. -G"Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%" -AWin32

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM