flomesh-io / ztm

ZTM (Zero Trust Mesh) is a privacy-first open-source decentralized network software based on HTTP/2 tunnels. Experience boundless connectivity and mesh the globe!
Apache License 2.0
330 stars 30 forks source link

Compilation Errors in zlib 1.3 #28

Closed genedna closed 3 months ago

genedna commented 5 months ago

During the compilation of zlib version 1.3 as a dependency in our project, multiple warnings and errors were generated related to macro redefinitions and macro expansions conflicting with standard library headers.

[ 21%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/adler32.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/adler32.c:8:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
1 warning generated.
[ 22%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/compress.c.o
[ 22%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/crc32.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/crc32.c:30:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
1 warning generated.
[ 22%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/deflate.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/deflate.c:52:
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/deflate.h:16:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
1 warning generated.
[ 22%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/gzclose.c.o
[ 23%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/gzlib.c.o
[ 23%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/gzread.c.o
[ 23%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/gzwrite.c.o
[ 24%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/inflate.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/inflate.c:83:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
1 warning generated.
[ 24%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/infback.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/infback.c:13:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
1 warning generated.
[ 24%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/inftrees.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/inftrees.c:6:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
1 warning generated.
[ 24%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/inffast.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/inffast.c:6:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
1 warning generated.
[ 25%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/trees.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/trees.c:37:
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/deflate.h:16:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
1 warning generated.
[ 25%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/uncompr.c.o
[ 25%] Building C object deps/zlib-1.3/CMakeFiles/zlibstatic.dir/zutil.c.o
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.c:8:
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:170:11: warning: 'OS_CODE' macro redefined [-Wmacro-redefined]
  170 | #  define OS_CODE 19
      |           ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:141:11: note: previous definition is here
  141 | #  define OS_CODE  7
      |           ^
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.c:10:
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/gzguts.h:20:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:220:7: error: expected identifier or '('
  220 | FILE    *fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen));
      |          ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:147:33: note: expanded from macro 'fdopen'
  147 | #        define fdopen(fd,mode) NULL /* No fdopen() */
      |                                 ^
/opt/homebrew/Cellar/llvm/18.1.6/lib/clang/18/include/__stddef_null.h:26:16: note: expanded from macro 'NULL'
   26 | #define NULL ((void*)0)
      |                ^
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.c:10:
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/gzguts.h:20:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:220:7: error: expected ')'
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:147:33: note: expanded from macro 'fdopen'
  147 | #        define fdopen(fd,mode) NULL /* No fdopen() */
      |                                 ^
/opt/homebrew/Cellar/llvm/18.1.6/lib/clang/18/include/__stddef_null.h:26:16: note: expanded from macro 'NULL'
   26 | #define NULL ((void*)0)
      |                ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:220:7: note: to match this '('
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:147:33: note: expanded from macro 'fdopen'
  147 | #        define fdopen(fd,mode) NULL /* No fdopen() */
      |                                 ^
/opt/homebrew/Cellar/llvm/18.1.6/lib/clang/18/include/__stddef_null.h:26:15: note: expanded from macro 'NULL'
   26 | #define NULL ((void*)0)
      |               ^
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.c:10:
In file included from /Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/gzguts.h:20:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:220:7: error: expected ')'
  220 | FILE    *fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen));
      |          ^
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:147:33: note: expanded from macro 'fdopen'
  147 | #        define fdopen(fd,mode) NULL /* No fdopen() */
      |                                 ^
/opt/homebrew/Cellar/llvm/18.1.6/lib/clang/18/include/__stddef_null.h:26:22: note: expanded from macro 'NULL'
   26 | #define NULL ((void*)0)
      |                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/stdio.h:220:7: note: to match this '('
/Users/eli/GitMono/ztm/pipy/deps/zlib-1.3/zutil.h:147:33: note: expanded from macro 'fdopen'
  147 | #        define fdopen(fd,mode) NULL /* No fdopen() */
      |                                 ^
/opt/homebrew/Cellar/llvm/18.1.6/lib/clang/18/include/__stddef_null.h:26:14: note: expanded from macro 'NULL'
   26 | #define NULL ((void*)0)
      |              ^
1 warning and 3 errors generated.
make[2]: *** [deps/zlib-1.3/CMakeFiles/zlibstatic.dir/zutil.c.o] Error 1
make[1]: *** [deps/zlib-1.3/CMakeFiles/zlibstatic.dir/all] Error 2
keveinliu commented 4 months ago

Which OS were you compiling the ztm on? We'll give a try on that OS. Thanks!

naqvis commented 4 months ago

This is known bug of Zlib 1.3. Workaround is to use LLVM < 16

NB: Bug has been fixed in Zlib 1.3.1 and We will be upgrading pipy dependency to that version soon.

xiaods commented 4 months ago

use zig build system can resolved this issues.

keveinliu commented 4 months ago

@genedna Hi, we've bump up zlib to 1.3.1. Should have solved this problem. Please give a try.

pipy commit id: 370bf9aff8650fd7c7e930bbfbfcb4edbf433b36