Clang archive or linking issue. Xcode 15.0.1

I have issues building my project on C, and I have created minimal build to reproduce the issue. Project uses .a archive for linking, the error:

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

Archive to try: https://file.io/OomLs7yTSAnz

Files:

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;
}

same problem! that's crazy! xcode14 works.

Same issue with clang (from brew) + cmake + clion

Same issue here. I was unable to compile the Telegram desktop client on my macOS 14.4 machine.

Having the same issues here, gcc from brew and macOS 14.3.1

Hello, as reported here there are several things that can lead to this problem :

  • using GCC instead of XCode-provided CLang
  • having Coreutils or Binutils in your env PATH.

Try to remove any reference from your env PATH before compiling again.

Clang archive or linking issue. Xcode 15.0.1
 
 
Q