You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apple M1 Pro芯片MacBook Pro编译zlib库arm64符号未定义问题解决

在Apple M1 Pro上编译zlib 1.2.11出现arm64架构未定义符号错误

从zlib官网下载zlib 1.2.11库,在2021款搭载Apple M1 Pro芯片的MacBook Pro上执行./configure和make命令后,出现arm64架构下未定义符号的链接错误,完整执行日志如下:

~/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

环境信息

clang版本及PATH环境变量如下:

~ > 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

解决方法

方法1:使用Homebrew安装(推荐)

直接通过Homebrew获取适配arm64的预编译zlib:

brew install zlib

方法2:修复手动编译的符号隐藏问题

错误根源是HAVE_HIDDEN编译选项导致静态库中的符号被隐藏,无法被链接。执行以下步骤修复:

  • 清理现有编译产物:
    make clean
    
  • 重新配置,禁用符号隐藏:
    ./configure --disable-hidden
    
  • 重新编译:
    make
    

方法3:强制指定clang编译器

如果上述方法无效,可强制使用clang作为编译器并明确指定arm64架构:

  • 清理后重新配置:
    make clean
    CC=clang CFLAGS="-O3 -arch arm64" ./configure
    
  • 编译:
    make
    

内容的提问来源于stack exchange,提问作者yanran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 11:18:37