C项目突然无法在macOS上编译“为macOS-x86_64构建,但试图链接为未知-arm 64构建的文件”

p1tboqfb  于 2023-08-03  发布在  Mac
关注(0)|答案(3)|浏览(242)

问题

在过去的几周里,我一直在做一个基于Intel ISA-L库的纠删编码项目。
一切都很顺利,因为我只是调试了一段时间,然后我离开了大约一天的项目。我返回继续调试,没有对代码或我的Macbook(据我所知)进行任何更改,我试图再次编译代码作为调试过程的一部分,我得到了以下错误:

ld: warning: -undefined dynamic_lookup is incompatible with dyld share cache
ld: warning: ignoring file raid/.libs/raid_base.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file erasure_code/.libs/ec_base.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file crc/.libs/crc_base.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file crc/.libs/crc64_base.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/hufftables_c.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/igzip.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/igzip_base.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/igzip_icf_base.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/adler32_base.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/encode_df.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/flatten_ll.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/igzip_icf_body.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file mem/.libs/mem_zero_detect_base.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/huff_codes.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file igzip/.libs/igzip_inflate.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: -undefined dynamic_lookup cannot be used to find '_ec_encode_data_base' in dylib in dyld shared cache for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libisal.la] Error 1

字符串
我已经尝试了我在Stack Overflow和其他在线资源上看到的几个潜在的解决方案,但没有一个有效。我还尝试在标准ISA-L库上编译代码,而不向其中添加任何额外的代码,但出现了同样的问题。

附加信息:

  • 我正在开发一款2020年的MacBook Pro,它运行在macOS Monterey 12.5上,采用M1 Apple芯片。
  • 下面是clang --version的输出:
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

  • 下面是echo $PATH的输出:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

  • Makefile非常复杂,我认为它是由英特尔ISA-L库中的某些代码自动生成的,所以我没有在这里介绍它,但我希望这不是我的情况所特有的问题,并且有一个通用的修复方法可以适用于许多情况。
  • 如果需要其他细节,请告诉我。
sqxo8psd

sqxo8psd1#

链接中的答案对我有用。https://stackoverflow.com/a/71886952/20189614
我在将cmake更新到版本3.24.2后解决了这个问题。

busg9geu

busg9geu2#

我找到了一个解决方案,帮助我解决了这个问题(尽管它发现了一个更深层次的不相关的bug),我认为这可能对其他人有帮助。
显然,由于我在M1 MacBook Pro上运行,clang --version的输出应该是arm64-apple-darwin21.6.0而不是x86_64-apple-darwin21.6.0
运行命令arch也返回i3864而不是arm64,这是一个问题。
为了解决这个问题,我运行了以下命令:

env /usr/bin/arch -arm64 /bin/zsh --login

字符串
我不确定这是一个彻底的解决方案还是只是一个快速修复,但在重新启动后,我得到了与ARM的编译。

zyfwsgd6

zyfwsgd63#

我也遇到过类似的问题(使用mpicc),我通过使用选项arch arm 64更改clang的架构解决了这个问题。您可以通过输入clang -arch arm 64--version(或mpicc -arch arm 64--version,在我的例子中)来检查更改。

clang version 14.0.6
Target: arm64-apple-darwin21.6.0
Thread model: posix

字符串

相关问题