mapsme / omim

πŸ—ΊοΈ MAPS.ME β€” Offline OpenStreetMap maps for iOS and Android
Apache License 2.0
4.57k stars 1.15k forks source link

Bundled minizip does not compile when zlib is installed #3808

Open krisk0 opened 8 years ago

krisk0 commented 8 years ago

I managed to natively build MAPS.ME executable on a Gentoo/x86_64 desktop.

For that to happen, I had to remove bundled minizip library. I describe the problem and salvation below.

On my computer /usr/include/zlib.h is included when compiling minizip/zip.c, but not freetype/src/gzip/zlib.h. Which means freetype/src/gzip/zconf.h is never included and OF() macro is never defined. Therefore every line using this macro such as local int zip64local_putValue OF((const zlib_fil... triggers compiler error.

This is a standard problem: big library bundles smaller library which does exactly the same as already-installed system library; the smaller library does not compile because already-installed library interferes. And I solved it in standard way: removed the bundled version of minizip and disabled creation of minizip.a:

rm -rf 3party/minizip

for i in `find . -type f -name '*.pro'` ; do
 sed -e s:minizip::g -i $i || exit
done

cd coding
sed -e s:3party/minizip:minizip:g -i zip_creator.cpp zip_reader.cpp || exit
cd ..

I am 99% sure that everybody with correctly installed zlib library and using clang 3.8.0 should experience the compilation problem described above. I therefore hope that this post saves time for many Linux users.

Zverik commented 8 years ago

It is very strange, since maps.me compiles okay on mac os, ubuntu, centos and fedora (and even on windows for some). It uses only bundled libraries. If some external libraries are leaking in, then there must be an issue in ours or your build configuration.

krisk0 commented 8 years ago

Is /usr/include/zlib.h installed on Ubuntu?

If yes then clang on my computer chooses it and clang on Ubuntu chooses 3party/freetype/src/gzip/zlib.h. That's strange.

krisk0 commented 8 years ago

Compilation started with command

CONFIG=no-tests tools/unix/build_omim.sh -o -r 2>&1 | tee /tmp/build-omim.cout

Failed command:

clang -c -pipe -fdata-sections -ffunction-sections -O3 -ffast-math -g -fPIC -w -D_REENTRANT -DRELEASE -D_RELEASE -DNDEBUG -DUSE_FILE32API -DNOCRYPT -DQT_NO_DEBUG -I/tmp/omim-android-release-603/3party/minizip -I. -I/tmp/omim-android-release-603 -I/tmp/omim-android-release-603/3party/boost -I/tmp/omim-android-release-603/3party/glm -I/tmp/omim-android-release-603/3party/minizip -I/usr/lib64/qt5/mkspecs/linux-clang-libc++ -o ../../out/release/tmp/minizip/unzip.o /tmp/omim-android-release-603/3party/minizip/unzip.c

Error message:

In file included from /tmp/omim-android-release-603/3party/minizip/unzip.c:76:
In file included from /tmp/omim-android-release-603/3party/minizip/unzip.h:55:
/tmp/omim-android-release-603/3party/minizip/ioapi.h:135:45: error: expected ';' after top level declarator
typedef voidpf   (ZCALLBACK *open_file_func)      OF((voidpf opaque, const char* filename, int mode));

Preprocessed file reveals that /usr/include/zlib.h is included from line 70 of file 3party/minizip/unzip.c:

# 1278 "/usr/include/bits/string2.h" 3 4
extern char *__strdup (const char *__string) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__));
# 1297 "/usr/include/bits/string2.h" 3 4
extern char *__strndup (const char *__string, size_t __n)
     __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__));
# 631 "/usr/include/string.h" 2 3 4
# 70 "/tmp/omim-android-release-603/3party/minizip/unzip.c" 2

# 1 "/usr/include/zlib.h" 1 3 4
# 34 "/usr/include/zlib.h" 3 4

gcc with compilation options as above produces no error because it takes includes from directories specified via -I switch before system files such as /usr/include/... .

rinigus commented 8 years ago

I have the same/similar failure on Gentoo using bundled minizip:

gcc -c -pipe -fdata-sections -ffunction-sections -O3 -ffast-math -ffloat-store -g -fPIC -w -D_REENTRANT -DRELEASE -D_RELEASE -DNDEBUG -DUSE_FILE32API -DNOCRYPT -DQT_NO_DEBUG -I. -I../.. -I../../3party/boost -I../../3party/glm -I. -I/usr/lib64/qt5/mkspecs/linux-g++ -o ../../out/release/tmp/minizip/unzip.o unzip.c In file included from unzip.h:55:0, from unzip.c:76: ioapi.h:135:51: error: expected β€˜=’, β€˜,’, β€˜;’, β€˜asm’ or β€˜attribute’ before β€˜OF’ typedef voidpf (ZCALLBACK _open_filefunc) OF((voidpf opaque, const char filename, int mode)); ^ ioapi.h:136:51: error: expected β€˜=’, β€˜,’, β€˜;’, β€˜asm’ or β€˜attribute’ before β€˜OF’ typedef uLong (ZCALLBACK _read_filefunc) OF((voidpf opaque, voidpf stream, void buf, uLong size)); ^ ioapi.h:137:51: error: expected β€˜=’, β€˜,’, β€˜;’, β€˜asm’ or β€˜attribute’ before β€˜OF’ typedef uLong (ZCALLBACK _write_filefunc) OF((voidpf opaque, voidpf stream, const void buf, uLong size));

rinigus commented 8 years ago

I managed to compile it on gentoo after following the advice in the first post. In addition, I had to add

LIBS += -lminizip

in common.pri