2

I downloaded zlib from https://zlib.net/ and execute ./configure and make cmd. However, it shows that there are some undefined symbols for architecture arm64. How to build zlib in this case? I'm using a macbookpro 2021 with apple m1pro chip. The full info is:

~/GitClone/zlib-1.2.11 > ./configure                                                                                                                                                                                              at 15:42:53
Checking for gcc...
Checking for shared library support...
Building shared library libz.1.2.11.dylib with gcc.
Checking for size_t... Yes.
Checking for off64_t... No.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
~/GitClone/zlib-1.2.11 > make                                                                                                                                                                                                     at 15:43:13
gcc -O3 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -O3 -DHAVE_HIDDEN  -c -o adler32.o adler32.c
gcc -O3 -DHAVE_HIDDEN  -c -o crc32.o crc32.c
gcc -O3 -DHAVE_HIDDEN  -c -o deflate.o deflate.c
gcc -O3 -DHAVE_HIDDEN  -c -o infback.o infback.c
gcc -O3 -DHAVE_HIDDEN  -c -o inffast.o inffast.c
gcc -O3 -DHAVE_HIDDEN  -c -o inflate.o inflate.c
gcc -O3 -DHAVE_HIDDEN  -c -o inftrees.o inftrees.c
gcc -O3 -DHAVE_HIDDEN  -c -o trees.o trees.c
gcc -O3 -DHAVE_HIDDEN  -c -o zutil.o zutil.c
gcc -O3 -DHAVE_HIDDEN  -c -o compress.o compress.c
gcc -O3 -DHAVE_HIDDEN  -c -o uncompr.o uncompr.c
gcc -O3 -DHAVE_HIDDEN  -c -o gzclose.o gzclose.c
gcc -O3 -DHAVE_HIDDEN  -c -o gzlib.o gzlib.c
gcc -O3 -DHAVE_HIDDEN  -c -o gzread.o gzread.c
gcc -O3 -DHAVE_HIDDEN  -c -o gzwrite.o gzwrite.c
libtool -o 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 -O3 -DHAVE_HIDDEN -o example example.o -L. libz.a
ld: warning: ignoring file libz.a, building for macOS-arm64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture arm64:
  "_compress", referenced from:
      _test_compress in example.o
     (maybe you meant: _test_compress)
  "_deflate", referenced from:
      _test_deflate in example.o
      _test_large_deflate in example.o
      _test_flush in example.o
      _test_dict_deflate in example.o
     (maybe you meant: _test_large_deflate, _test_deflate , _test_dict_deflate )
  "_deflateEnd", referenced from:
      _test_deflate in example.o
      _test_large_deflate in example.o
      _test_flush in example.o
      _test_dict_deflate in example.o
  "_deflateInit_", referenced from:
      _test_deflate in example.o
      _test_large_deflate in example.o
      _test_flush in example.o
      _test_dict_deflate in example.o
  "_deflateParams", referenced from:
      _test_large_deflate in example.o
  "_deflateSetDictionary", referenced from:
      _test_dict_deflate in example.o
  "_gzclose", referenced from:
      _test_gzio in example.o
  "_gzerror", referenced from:
      _test_gzio in example.o
  "_gzgetc", referenced from:
      _test_gzio in example.o
  "_gzgets", referenced from:
      _test_gzio in example.o
  "_gzopen", referenced from:
      _test_gzio in example.o
  "_gzprintf", referenced from:
      _test_gzio in example.o
  "_gzputc", referenced from:
      _test_gzio in example.o
  "_gzputs", referenced from:
      _test_gzio in example.o
  "_gzread", referenced from:
      _test_gzio in example.o
  "_gzseek", referenced from:
      _test_gzio in example.o
  "_gztell", referenced from:
      _test_gzio in example.o
  "_gzungetc", referenced from:
      _test_gzio in example.o
  "_inflate", referenced from:
      _test_inflate in example.o
      _test_large_inflate in example.o
      _test_sync in example.o
      _test_dict_inflate in example.o
     (maybe you meant: _test_large_inflate, _test_inflate , _test_dict_inflate )
  "_inflateEnd", referenced from:
      _test_inflate in example.o
      _test_large_inflate in example.o
      _test_sync in example.o
      _test_dict_inflate in example.o
  "_inflateInit_", referenced from:
      _test_inflate in example.o
      _test_large_inflate in example.o
      _test_sync in example.o
      _test_dict_inflate in example.o
  "_inflateSetDictionary", referenced from:
      _test_dict_inflate in example.o
  "_inflateSync", referenced from:
      _test_sync in example.o
  "_uncompress", referenced from:
      _test_compress in example.o
  "_zlibCompileFlags", referenced from:
      _main in example.o
  "_zlibVersion", referenced from:
      _main in example.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [example] Error 1

The clang version and environment variable is like:

~ > clang --version                                                                                       at 16:22:31
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
~ > clang++ --version                                                                                     at 16:22:34
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
~ > echo $PATH                                                                                            at 16:22:37
/usr/local/include:/opt/homebrew/Cellar/binutils/2.38_1/bin:/Users/hanxiaohao/.npm-global/bin:/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home/bin:/opt/homebrew/Cellar/binutils/2.38_1/bin:/Users/hanxiaohao/.npm-global/bin:/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/hanxiaohao/Library/Application Support/JetBrains/Toolbox/scripts:/opt/homebrew/Cellar/maven/3.6.3/bin:/opt/homebrew/Cellar/maven/3.6.3/bin
yanran
  • 33
  • 5
  • It seem that the `libz.a` library is "ignored" by the linker, therefore the functions defined in the library can't be found leading to the errors. – Some programmer dude Sep 05 '22 at 07:56
  • I would suggest that you use zlib-ng. The original zlib looks like frozen in i386 of nineties. – 273K Sep 05 '22 at 08:00
  • Very strange. I have built a fresh new zlib on my sillicon M1Max without any error. – halfelf Sep 05 '22 at 08:08
  • Could you post your environment variables and clang version? – halfelf Sep 05 '22 at 08:11
  • Unrelated: zlib 1.2.12 was released on March 27, 2022 so use that rather than 1.2.11. – Ted Lyngmo Sep 05 '22 at 08:16
  • 3
    possible duplicate? https://stackoverflow.com/questions/71285115/cannot-link-library-for-macos-arm64-with-executable-for-macos-arm64 – Alan Birtles Sep 05 '22 at 08:23
  • It works for me every time. (Especially seeing as how I _develop_ zlib on my M1 MacBook Pro.) You must have something non-standard installed on your system. Perhaps libtool? ld? I see homebrew in your path. – Mark Adler Sep 05 '22 at 13:04
  • By the way, your path is redundant. binutils repeated twice, Java jdk repeated twice, "/Users/hanxiaohao/.npm-global/bin" repeated twice. You have been sloppy with your installs. In any case, it looks like binutils is overriding the standard Apple build utilities, including `ld`. – Mark Adler Sep 05 '22 at 13:14

1 Answers1

1

Not reproducible.

Tested on M1 Max macOS 12.5.1 with XCode 13.4.1 and Homebrew in the /opt/homebrew directory.

I noticed you have /usr/local/include and /usr/local/bin in your path. Those should be non-existent on M1 macOS. They were for Homebrew Intel.

% ls -l /usr/local/include /usr/local/bin
ls: /usr/local/bin: No such file or directory
ls: /usr/local/include: No such file or directory

Here is the run log of my test:

% ./configure
Checking for gcc...
Checking for shared library support...
Building shared library libz.1.2.12.dylib with gcc.
Checking for size_t... Yes.
Checking for off64_t... No.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
% make
gcc -O3 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -O3 -DHAVE_HIDDEN  -c -o adler32.o adler32.c
gcc -O3 -DHAVE_HIDDEN  -c -o crc32.o crc32.c
gcc -O3 -DHAVE_HIDDEN  -c -o deflate.o deflate.c
gcc -O3 -DHAVE_HIDDEN  -c -o infback.o infback.c
gcc -O3 -DHAVE_HIDDEN  -c -o inffast.o inffast.c
gcc -O3 -DHAVE_HIDDEN  -c -o inflate.o inflate.c
gcc -O3 -DHAVE_HIDDEN  -c -o inftrees.o inftrees.c
gcc -O3 -DHAVE_HIDDEN  -c -o trees.o trees.c
gcc -O3 -DHAVE_HIDDEN  -c -o zutil.o zutil.c
gcc -O3 -DHAVE_HIDDEN  -c -o compress.o compress.c
gcc -O3 -DHAVE_HIDDEN  -c -o uncompr.o uncompr.c
gcc -O3 -DHAVE_HIDDEN  -c -o gzclose.o gzclose.c
gcc -O3 -DHAVE_HIDDEN  -c -o gzlib.o gzlib.c
gcc -O3 -DHAVE_HIDDEN  -c -o gzread.o gzread.c
gcc -O3 -DHAVE_HIDDEN  -c -o gzwrite.o gzwrite.c
libtool -o 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 -O3 -DHAVE_HIDDEN -o example example.o -L. libz.a
gcc -O3 -DHAVE_HIDDEN -I. -c -o minigzip.o test/minigzip.c
gcc -O3 -DHAVE_HIDDEN -o minigzip minigzip.o -L. libz.a
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/adler32.o adler32.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/crc32.o crc32.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/deflate.o deflate.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/infback.o infback.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/inffast.o inffast.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/inflate.o inflate.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/inftrees.o inftrees.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/trees.o trees.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/zutil.o zutil.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/compress.o compress.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/uncompr.o uncompr.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/gzclose.o gzclose.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/gzlib.o gzlib.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/gzread.o gzread.c
gcc -O3 -fPIC -DHAVE_HIDDEN  -DPIC -c -o objs/gzwrite.o gzwrite.c
gcc -dynamiclib -install_name /usr/local/lib/libz.1.dylib -compatibility_version 1 -current_version 1.2.12 -O3 -fPIC -DHAVE_HIDDEN -o libz.1.2.12.dylib adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo  -lc
rm -f libz.dylib libz.1.dylib
ln -s libz.1.2.12.dylib libz.dylib
ln -s libz.1.2.12.dylib libz.1.dylib
gcc -O3 -DHAVE_HIDDEN -o examplesh example.o -L. libz.1.2.12.dylib
gcc -O3 -DHAVE_HIDDEN -o minigzipsh minigzip.o -L. libz.1.2.12.dylib
% gcc --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% clang++ --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% uname -a
Darwin Superbook.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 arm64
James Risner
  • 5,451
  • 11
  • 25
  • 47