Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: unknown type name ‘z_size_t’ from test/minigzip.c #772

Closed
kirankotari opened this issue Jan 26, 2023 · 10 comments
Closed

error: unknown type name ‘z_size_t’ from test/minigzip.c #772

kirankotari opened this issue Jan 26, 2023 · 10 comments

Comments

@kirankotari
Copy link

kirankotari commented Jan 26, 2023

Hi Team,

I am pretty confused at this point, I saw z_size_t was defined in the zconf.h and it's has been included in zlib.h
Looking for help what to do at this point.

From zconf.h

#ifdef Z_SOLO
   typedef unsigned long z_size_t;
#else
#  define z_longlong long long
#  if defined(NO_SIZE_T)
     typedef unsigned NO_SIZE_T z_size_t;
#  elif defined(STDC)
#    include <stddef.h>
     typedef size_t z_size_t;
#  else
     typedef unsigned long z_size_t;
#  endif
#  undef z_longlong
#endif

How to reproduce the error:
OS: PRETTY_NAME="CentOS Linux 7 (Core)"
Zlib version: zlib-1.2.13.tar

This error occurred on make

Error log:

[root@test ~/install-test/zlib-1.2.13]# make clean
rm -f *.o *.lo *~ \
   example minigzip examplesh minigzipsh \
   example64 minigzip64 \
   infcover \
   libz.* foo.gz so_locations \
   _match.s maketree contrib/infback9/*.o
rm -rf objs
rm -f *.gcda *.gcno *.gcov
rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
[root@test ~/install-test/zlib-1.2.13]# make
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o adler32.o adler32.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o crc32.o crc32.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o deflate.o deflate.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o infback.o infback.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o inffast.o inffast.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o inflate.o inflate.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o inftrees.o inftrees.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o trees.o trees.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o zutil.o zutil.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o compress.o compress.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o uncompr.o uncompr.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzclose.o gzclose.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzlib.o gzlib.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzread.o gzread.c
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN  -c -o gzwrite.o gzwrite.c
ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o example example.o -L/usr/local/zlib/lib -L/usr/bin/openssl -L. libz.a
gcc -I/usr/local/zlib/include -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o minigzip.o test/minigzip.c
test/minigzip.c: In function ‘file_uncompress’:
test/minigzip.c:503:5: error: unknown type name ‘z_size_t’
     z_size_t len = strlen(file);
     ^
make: *** [minigzip.o] Error 1
[root@test ~/install-test/zlib-1.2.13]#

Let me know if any more details needed.
Thanks for the contributions.

@madler
Copy link
Owner

madler commented Jan 28, 2023

I just tried zlib 1.2.13 on "CentOS Linux release 7.9.2009 (AltArch)" with ./configure and make test, and worked fine.

Why does your compile have the -I/usr/local/zlib/include option? Did you put that in? It should not be including from there. It should be including the zlib header files from the directory you are building in.

@etiennearnal
Copy link

etiennearnal commented Feb 1, 2023

Hi @madler,

I get the same error than @kirankotari on zlib v1.2.13.
I try to compile from CMake using

CPMAddPackage(
NAME zlibstatic
GIT_REPOSITORY "https://github.com/madler/zlib.git"
GIT_TAG "v1.2.13"
OPTIONS
"SKIP_INSTALL_ALL ON"
)

And I get this error:

[build] [6/13 7% :: 0.022] Linking C static library _deps/zlibstatic-build/libz.a
[build] [7/13 15% :: 0.040] Linking C static library libminizip.a
[build] [7/13 23% :: 0.057] Building C object _deps/zlibstatic-build/CMakeFiles/minigzip.dir/test/minigzip.o
[build] FAILED: _deps/zlibstatic-build/CMakeFiles/minigzip.dir/test/minigzip.o
[build] /opt/gcc-8.2.0/bin/gcc -D_LARGEFILE64_SOURCE=1 -I_deps/zlibstatic-build -I../ -g -fPIE -MD -MT _deps/zlibstatic-build/CMakeFiles/minigzip.dir/test/minigzip.o -MF _deps/zlibstatic-build/CMakeFiles/minigzip.dir/test/minigzip.o.d -o _deps/zlibstatic-build/CMakeFiles/minigzip.dir/test/minigzip.o -c _deps/zlibstatic-src/test/minigzip.c
[build] _deps/zlibstatic-src/test/minigzip.c: In function ‘file_uncompress’:
[build] _deps/zlibstatic-src/test/minigzip.c:503:5: error: unknown type name ‘z_size_t’; did you mean ‘size_t’?
[build] z_size_t len = strlen(file);
[build] ^~~~~~~~
[build] size_t
[build] [7/13 30% :: 0.058] Building C object _deps/zlibstatic-build/CMakeFiles/minigzip64.dir/test/minigzip.o
[build] FAILED: _deps/zlibstatic-build/CMakeFiles/minigzip64.dir/test/minigzip.o

I checked in zconf.h
image

I'm on CentOS Linux release 7.9.2009 (Core) with Gcc8.2

@etiennearnal
Copy link

Just to add some information, with same agent and same compiler, it fails on 1.2.13 but succeed with 1.2.12...

@kirankotari
Copy link
Author

@madler I have added this as part of other software, do you want me to remove before installing zlib? I can do that and test for you.

Note:-
For a work around we skipped make and went forward with make install

@etiennearnal
Copy link

etiennearnal commented Feb 1, 2023

@kirankotari I fount the issue. I discovered that zlib.h was including the zconf.h located in /usr/include, which is quite old and doesn't define z_size_t...

Workaround is to add this in minigzip.c:

#include <stddef.h>
typedef size_t z_size_t;

I think the issue is related to the commit 2d6d59e. And my compiler (Intel icpc) use /usr/include folder because it define it in environment variable CPLUS_INCLUDE_PATH. 😡

@etiennearnal
Copy link

etiennearnal commented Feb 2, 2023

@madler I think there is an issue in zlib CMakeLists.txt...
When compiling minigzip.c, compiler is started from ${CMAKE_BINARY_DIR}, where zconf.h is present.
But minigzip.c include "zlib.h" (which will include "zconf.h"). But as zlib.h is not present in build folder. So compiler will check on system include directories (/usr/include, gcc, ...) and can find an old zlib.h.

To be sure to include the good zlib.h, I think that main CMakelists.txt should copy zlib.h into build directory.

@nmoinvaz
Copy link
Contributor

nmoinvaz commented Feb 2, 2023

These changes might help you:
https://github.com/madler/zlib/pull/343/files

@aschmitz-crnc
Copy link

@madler Same issue here on CentOS and Android. The change by @nmoinvaz helped perfectly.

@Neustradamus
Copy link

@madler: Can you look this issue?

There are several comments and previously, @nmoinvaz has answered with this PR:

nfbvs added a commit to ampl/plugins that referenced this issue Jan 21, 2024
nfbvs added a commit to ampl/plugins that referenced this issue Jan 21, 2024
@madler
Copy link
Owner

madler commented Jan 22, 2024

Possibly fixed with 2e3d86c .

@madler madler closed this as completed Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants