wolfpld / etcpak

The fastest ETC compressor on the planet
Other
229 stars 41 forks source link

Fix error implicit declaration of function 'lseek' on MacOS #29

Closed panzhongxian closed 2 years ago

panzhongxian commented 2 years ago

When cd to unix and execute make release on MacOS, we will get the error:

cc -c -I../zlib -g3 -Wall -msse4.1 -DNO_GZIP -DSTDC -DPNG_INTEL_SSE -DDEBUG  ../zlib/gzlib.c -o ../zlib/gzlib.o
../zlib/gzlib.c:252:9: error: implicit declaration of function 'lseek' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
        ^
../zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
#  define LSEEK lseek
                ^
../zlib/gzlib.c:252:9: note: did you mean 'fseek'?
../zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
#  define LSEEK lseek
                ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:162:6: note: 'fseek' declared here
int      fseek(FILE *, long, int);
         ^

Fix the error by adding #include <unistd.h> explicitly.

wolfpld commented 2 years ago

Please submit same fix to upstream zlib, then link it here. Thanks.

panzhongxian commented 2 years ago

Hi, @wolfpld I read the zlib code. In zlib, when we call ./configure, the unistd.h will be checked. If the file exists, file zconf.h will be modified FROM:

#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
#  define Z_HAVE_UNISTD_H
#endif

TO:

#if 1    /* was set to #if 1 by ./configure */
#  define Z_HAVE_UNISTD_H
#endif

While we use the build.sh and Makefile in etcpak, this checking are not executed.

I push a new commit, in which I only changed the build.mk to add a definition instead of changing zlib source code. Since unistd.h is a poxis api header file, I believe the change of unix/build.mk is acceptable. Please check it.