ld: warning: ignoring file LIB, building for ARCH but attempting to link with file built for ARCH

错误重放

作者在编译edk2/BaseTools时出现以下问题:

➜  BaseTools uname -a
Darwin MacBook-Pro.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64 x86_64 #作者环境
······
➜  BaseTools make
······
clang++ -o ../bin/VfrCompile  AParser.o DLexerBase.o ATokenBuffer.o EfiVfrParser.o VfrLexer.o VfrSyntax.o VfrFormPkg.o VfrError.o VfrUtilityLib.o VfrCompiler.o -L../libs -lCommon
ld: warning: ignoring file ../libs/libCommon.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture x86_64:
  "_DebugMsg", referenced from:
      CVfrCompiler::OptionInitialization(int, char**) in VfrCompiler.o
      CVfrCompiler::AdjustBin() in VfrCompiler.o
  "_Error", referenced from:
      CVfrErrorHandle::PrintMsg(unsigned int, char*, char const*, char const*) in VfrError.o
      CVfrErrorHandle::HandleError(EFI_VFR_RETURN_CODE, unsigned int, char*) in VfrError.o
      CVfrErrorHandle::HandleWarning(EFI_VFR_WARNING_CODE, unsigned int, char*) in VfrError.o
  "_GetUtilityStatus", referenced from:
      _main in VfrCompiler.o
  "_LongFilePath", referenced from:
      CVfrStringDB::GetVarStoreNameFormStringId(unsigned short) in VfrUtilityLib.o
      CVfrCompiler::PreProcess() in VfrCompiler.o
      CVfrCompiler::Compile() in VfrCompiler.o
      CVfrCompiler::GenBinary() in VfrCompiler.o
      CVfrCompiler::GenCFile() in VfrCompiler.o
      CVfrCompiler::GenRecordListFile() in VfrCompiler.o
  "_PrintMessage", referenced from:
      CVfrCompiler::DebugError(char*, unsigned int, unsigned int, char const*, char const*, ...) in VfrCompiler.o
  "_SetPrintLevel", referenced from:
      _main in VfrCompiler.o
  "_SetUtilityName", referenced from:
      CVfrCompiler::OptionInitialization(int, char**) in VfrCompiler.o
  "_StringToGuid", referenced from:
      CVfrCompiler::OptionInitialization(int, char**) in VfrCompiler.o
  "_VerboseMsg", referenced from:
      CVfrErrorHandle::PrintMsg(unsigned int, char*, char const*, char const*) in VfrError.o
  "_Warning", referenced from:
      CVfrErrorHandle::HandleWarning(EFI_VFR_WARNING_CODE, unsigned int, char*) in VfrError.o
ld: symbol(s) not found for architecture x86_64
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [GNUmakefile:45: ../bin/VfrCompile] Error 1

错误原因

该问题是由于程序需要../libs/libCommon.a但链接器ld无法链接libCommon.a导致的链接错误
经检查后发现由于作者电脑上安装了包括CommandLineTools llvm gnucc的3套编译环境,由于llvm-14 llvm-16 gnubinutils、语法和符号有所不同,所以导致了库文件不互相兼容的情况

解决方法

自行保留仅一套编译环境
以下仅供参考

brew unlink llvm binutils

export PATH=/usr/bin:/usr/sbin:/bin:/sbin
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值