使用 Homebrew (
brew install libpng
) 安装 libpng 后,尝试使用命令 gcc -o render_region.o render_region.c -I/usr/local/Cellar/libpng/1.6.43/include/libpng16 -L/usr/local/Cellar/libpng/1.6.43/lib -lpng16
编译项目会返回
ld: warning: ignoring file '/usr/local/Cellar/libpng/1.6.43/lib/libpng16.16.dylib': found architecture 'x86_64', required architecture 'arm64'
Undefined symbols for architecture arm64:
"_png_create_info_struct", referenced from:
_saveImage in render_region-26644b.o
"_png_create_write_struct", referenced from:
_saveImage in render_region-26644b.o
"_png_destroy_write_struct", referenced from:
_saveImage in render_region-26644b.o
_saveImage in render_region-26644b.o
_saveImage in render_region-26644b.o
"_png_init_io", referenced from:
_saveImage in render_region-26644b.o
"_png_set_IHDR", referenced from:
_saveImage in render_region-26644b.o
"_png_set_longjmp_fn", referenced from:
_saveImage in render_region-26644b.o
"_png_write_end", referenced from:
_saveImage in render_region-26644b.o
"_png_write_image", referenced from:
_saveImage in render_region-26644b.o
"_png_write_info", referenced from:
_saveImage in render_region-26644b.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
在网上搜索,我见过的唯一类似问题是通过在标志中添加
-I/usr/local/Cellar/libpng/1.6.43/include/libpng16 -L/usr/local/Cellar/libpng/1.6.43/lib -lpng16
来解决的。我通过 libpng-config --cflags --ldflags
添加标志,因此我验证了它添加的标志,但没有帮助。我还尝试重新安装并检查 libpng 站点。
我是否安装了错误的版本?还是链接错误?
(编辑)我的电脑有 M3 芯片。在与其他人交谈后,我确定问题的最初原因很可能是由于将我的个人资料(包括我的brew安装)从不使用Apple芯片的旧MacBook上带来的。
我向朋友展示了这个错误,他们意识到这很可能是由于我的个人资料从我的旧 MacBook 上带来的。
Homebrew 网站有关于是否安装了两种架构的说明,我能够修改它们以适应安装了错误的版本。
brew bundle dump --global
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew bundle install --global
之后文件编译良好。
当 M1 真正问世时,我已经离开我的笔记本电脑几年了,但如果你更新得足够远,错误看起来会与开始时有所不同。