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

Mac平台编译Match软件时clang链接错误求助

在Mac(arm64架构)编译Match 2.3.1时的链接错误解决思路

我是博士生,编程经验有限,在Mac(arm64架构)上编译Match 2.3.1软件时,执行make命令后反复出现clang: error: linker command failed with exit code 1错误。终端输出显示series.o、config.o、floatnan.o因架构不兼容(目标为macOS-arm64,但文件格式不被支持)被忽略,同时存在arm64架构下的未定义符号问题。

编译终端输出

p-oz-nb030mc:Match pferreira$ make
c++ -O4 -c match.cc -o match.o -Wall -g 
clang: warning: -O4 is equivalent to -O3 [-Wdeprecated]
c++ -O4 -c normalize.cc -o normalize.o -Wall -g 
clang: warning: -O4 is equivalent to -O3 [-Wdeprecated]
In file included from normalize.cc:35:
./series.hh:67:14: warning: unused function 'intervalmap' [-Wunused-function]
static float intervalmap(float i1b, float i1e, float i2b, 
             ^
1 warning generated.
c++ match.o series.o config.o normalize.o floatnan.o -o match 
ld: warning: ignoring file series.o, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x4C 0x01 0x1C 0x00 0x00 0x00 0x00 0x00 0xA4 0x74 0x08 0x00 0x92 0x00 0x00 0x00 )
ld: warning: ignoring file config.o, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x4C 0x01 0x0D 0x00 0x00 0x00 0x00 0x00 0x3A 0x44 0x05 0x00 0x5F 0x00 0x00 0x00 )
ld: warning: ignoring file floatnan.o, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x4C 0x01 0x0A 0x00 0x00 0x00 0x00 0x00 0x22 0x2F 0x02 0x00 0x28 0x00 0x00 0x00 )
Undefined symbols for architecture arm64:
  "read_gapfile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      getseries(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, float, int, floatnan, floatnan, std::__1::vector<floatnan, std::__1::allocator<floatnan> >, std::__1::vector<floatnan, std::__1::allocator<floatnan> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in match.o
  "read_tiefile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
      _main in match.o
  "merge_signal_series(std::__1::vector<series, std::__1::allocator<series> >&)", referenced from:
      getseries(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, float, int, floatnan, floatnan, std::__1::vector<floatnan, std::__1::allocator<floatnan> >, std::__1::vector<floatnan, std::__1::allocator<floatnan> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in match.o
  "readfile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      getseries(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, float, int, floatnan, floatnan, std::__1::vector<floatnan, std::__1::allocator<floatnan> >, std::__1::vector<floatnan, std::__1::allocator<floatnan> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in match.o
  "as_string(float)", referenced from:
      series::lookup_label(int, float) in match.o
  "as_string(int)", referenced from:
      write_new_series(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, path&, series&, series&, int) in match.o
      series::build_labelmap() in match.o
      series::lookup_label(int, float) in match.o
  "as_string(unsigned int)", referenced from:
      gaps::apply_gaps(series&) in match.o
  "config::read(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      _main in match.o
  "config::write(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
      _main in match.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [match] Error 1

Makefile内容

VERSION=2.3

all: match

%: %.o
    c++ $^ -o $@ $(LDFLAGS)

.cc.o:
#   c++ -c $< -o $@ -Wall -g $(CFLAGS)
    c++ -O4 -c $< -o $@ -Wall -g $(CFLAGS)

match: match.o series.o config.o normalize.o floatnan.o
match.o: match.cc config.hh series.hh normalize.hh floatnan.hh
series.o: series.cc series.hh floatnan.hh
config.o: config.cc config.hh floatnan.hh
normalize.o: normalize.cc normalize.hh series.hh floatnan.hh
floatnan.o: floatnan.cc floatnan.hh

clean: 
    rm -f *.o match *~ match.exe match.log *.new xmatch score_matrix

tar:
    sed '/\S/ ! d;s/^/Match-${VERSION}\/' ../manifest > ../manifest.tmp
    tar -cz -C ../.. -f ../match-${VERSION}.tgz -T ../manifest.tmp

check-manifest:
    cd .. && find . -type f | sed 's/^.\///' | grep -v ,v | sort > manifest.tmp
    sort ../manifest > ../manifest.tmp1
    diff ../manifest.tmp1 ../manifest.tmp; true
    pwd | grep 'Match-${VERSION}/' > /dev/null || (echo version mismatch; false)

解决思路

  • 清理旧目标文件:执行make clean,彻底删除所有已生成的.o目标文件和可执行文件,避免残留的旧架构文件干扰编译。
  • 修改Makefile指定架构:在Makefile开头添加以下两行,强制编译器生成arm64架构的代码:
    CFLAGS += -arch arm64
    LDFLAGS += -arch arm64
    
    同时可以把.cc.o规则里的-O4替换为-O3,消除clang的版本警告。
  • 重新编译:执行make命令,让编译器从头编译所有源文件,生成适配arm64架构的目标文件后再链接。
  • 确认终端架构:确保使用的是Mac原生arm64终端(而非Rosetta模拟的x86_64终端),可以通过执行uname -m查看输出是否为arm64来验证。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 22:50:26