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

Xcode 15.0.1+macOS Sonoma下Clang归档/链接问题求助

macOS Sonoma下静态库构建链接错误:archive member '/' not a mach-o file

构建依赖静态库的C项目时遇到链接错误,已制作最小复现项目。执行make命令后输出如下错误:

linker-test$ make
gcc -Wall -g -c -o main.o main.c
gcc -Wall -g -c -o ar-test1.o ar-test1.c
gcc -Wall -g -c -o ar-test2.o ar-test2.c
ar rcs libartest.a ar-test1.o ar-test2.o
gcc -Wall -g -o myapp main.o -L. -lartest
ld: archive member '/' not a mach-o file in '/Users/serg/temp/temp/linker-test/libartest.a'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [myapp] Error 1

升级到Sonoma系统后,发现GitHub上部分项目也出现相同的构建错误,有没有人解决过这个问题?


相关文件内容:

Makefile

CC = gcc
CFLAGS = -Wall -g

# List of source files and object files
SRCS = main.c
OBJS = $(SRCS:.c=.o)

# Archive name
LIBRARY = libartest.a

all: myapp

myapp: $(OBJS) $(LIBRARY)
    $(CC) $(CFLAGS) -o $@ $(OBJS) -L. -lartest

$(LIBRARY): ar-test1.o ar-test2.o
    ar rcs $(LIBRARY) ar-test1.o ar-test2.o

%.o: %.c
    $(CC) $(CFLAGS) -c -o $@ $<

clean:
    rm -f myapp $(OBJS) $(LIBRARY) *.o

.PHONY: all clean

ar-test1.c

#include <stdio.h>

void ar_test1() {
    printf("This is ar-test1.c\n");
}

ar-test2.c

#include <stdio.h>

void ar_test2() {
    printf("This is ar-test2.c\n");
}

main.c

#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 15:22:48