How to build zlib for arm64
Asked Answered
M

2

7

I use an open-source rendering library (Ogre3D) which has a dependency on zlib.

In XCode5, I noticed that when building for iOS, zlib will not build if 64-bit (arm64) architecture is indicated by ARCHS setting.

I get errors about "implicit function declaration" relating to LSEEK macro, read and write functions. I looked up LSEEK in gzlib.c:

#if defined(_WIN32) && !defined(__BORLANDC__)
#  define LSEEK _lseeki64
#else
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
#  define LSEEK lseek64
#else
#  define LSEEK lseek
#endif
#endif

My guess is something here is wrong, but I don't know what. And as for read() and write() I have no clue.

Mcneely answered 6/3, 2014 at 14:12 Comment(4)
We are using the official zlib library (version 1.2.8 as of yesterday), but we have a modified CMakeList.txt file, with many things stripped out. Perhaps compare ours to the one from the official zlib library to check if there are some mandatory things in order for it to compile on arm64 that we need to add.Bulb
BY 'we' you mean Ogre3D, right? I didn't realise customized versions were used.Mcneely
Yes, by 'we' I mean Ogre3D (or more specifically the Ogre3D dev team I am part of). Should have made that clearer,sorry. Again: The source code is the official version, just the CMakeList.txt is different.Bulb
Also: Did you try to manually define _LARGEFILE64_SOURCE and set _LFS64_LARGEFILE-0 to check whether used lseek64 would solve the issue?Bulb
K
12

Try adding an #include <unistd.h> in gzguts.h.

Konstanze answered 6/3, 2014 at 15:6 Comment(1)
Also works if you're having problems compiling zlib for OpenCV3.1.0. Thanks.Toting
B
1

The easiest solution in that scenario is not to build zlib yourself at all, since it already comes pre-compiled with the iOS SDK (also for arm64).

This latest commit fixes it also in the official Ogre dependencies repository.

Apart from that, there is this other option from this Ogre3D thread:

With ARCHS = ARCHS_STANDARD_INCLUDING_64_BIT, projects like zlip were failing. When I changed this to ARCHS_STANDARD_32_64_BIT, they built OK. I've discovered the former evaluates to "armv7 armv7s arm64" while the latter currently evaluates to "armv7 armv7s". So I think zlip won't build for arm64.

That would mean that Ogre3D parts are compiled for 64-bit, where as some dependencies such as zlib stay 32-bit.

Bulb answered 6/3, 2014 at 14:32 Comment(2)
I think that's just describing the same problem... it doesn't build for arm64. While not building for arm64 is an option, 32 bit apps introduce extra overhead on 64-bit iOS and it doesn't seem a long-term fix!Mcneely
I see and concur. Have a look at this answer then. Maybe adding that #include <unistd.h> solves the issue: https://mcmap.net/q/1479081/-how-to-compile-opencv-for-ios7-arm64Bulb

© 2022 - 2024 — McMap. All rights reserved.