List Archive

Thread

Thread Index

Message

From: Andreas Falkenhahn <andreas%falkenhahn.com@localhost>
To: Michał Janiszewski <janisozaur%gmail.com@localhost>
Subject: Re: Setting zlib path when compiling on Windows
Date: Tue, 3 Oct 2017 18:07:45 +0200

On 03.10.2017 at 15:14 Michał Janiszewski wrote:

> I'm not sure what your compiler is

Visual C.

It's working now but it was pretty much a pain in the arse... so just
for the record, here are the steps to build a static version of libzip
with /MT on Visual C:

1) Build zlib like this: 
cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release ..

2) Manually copy zconf.h into the main zlib distribution.

3) Build libzip like this:
cmake -DZLIB_INCLUDE_DIR=d:\mystuff\zlib-1.2.11 
-DZLIB_LIBRARY=d:\mystuff\zlib-1.2.11\build\zlibstatic.lib 
-DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release ..

Make sure to use absolute paths!!!

Before building both zlib and libzip it's also necessary to add the
following lines to CMakeLists.txt to force compilation with /MT
instead of /MD:

set(CompilerFlags
        CMAKE_CXX_FLAGS
        CMAKE_CXX_FLAGS_DEBUG
        CMAKE_CXX_FLAGS_RELEASE
        CMAKE_C_FLAGS
        CMAKE_C_FLAGS_DEBUG
        CMAKE_C_FLAGS_RELEASE
        )
foreach(CompilerFlag ${CompilerFlags})
  string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()

Note that I still get linker errors when libzip is trying to build
the example scripts:

hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_source_commit_write referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_source_rollback_write referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_source_write 
referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_source_read 
referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_source_close 
referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_source_begin_write referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_error_strerror 
referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_source_error 
referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_source_open 
referenced in function copy_source
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_error_fini 
referenced in function open_compressed
source_hole.c.obj : error LNK2001: unresolved external symbol 
__imp_zip_error_fini
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_error_init 
referenced in function open_compressed
source_hole.c.obj : error LNK2001: unresolved external symbol 
__imp_zip_error_init
hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_source_file_create referenced in function open_file
hole.c.obj : error LNK2019: unresolved external symbol __imp_zip_source_free 
referenced in function main
source_hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_source_seek_compute_offset referenced in function buffer_seek
source_hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_error_set referenced in function buffer_read_file
source_hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_source_make_command_bitmap referenced in function source_hole_cb
source_hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_error_to_data referenced in function source_hole_cb
source_hole.c.obj : error LNK2019: unresolved external symbol 
__imp_zip_source_function_create referenced in function source_hole_create
hole.exe : fatal error LNK1120: 18 unresolved externals

But I don't care about those. The lib itself is working fine but whoa, what a 
whole lot
of work just to build this rather simple lib. Next time I'm definitely just 
going to
hack the makefile together manually instead of wasting hours and hours trying to
understand weird build systems.

-- 
Best regards,
 Andreas Falkenhahn                            
mailto:andreas%falkenhahn.com@localhost

Made by MHonArc.