Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ld: file was built for unsupported file format on Mac OS X

Tags:

c

macos

I have to build a project with shared objects compiled on a other x64_86 computer. I have this error:

cc -std=c11 -Wall -Werror -Wextra -pedantic -I./include src/server.c
obj/tftp.o -o bin/server -L./lib64 -lSocketUDP -lAdresseInternet -lpthread
ld: warning: ld: warning: ignoring file ./lib64/libSocketUDP.so, file was
built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture
being linked (x86_64): ./lib64/libSocketUDP.soignoring file
./lib64/libAdresseInternet.so, file was built for unsupported file format (
0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 ) which is not the architecture being linked (x86_64):
./lib64/libAdresseInternet.so

The architecture of my Mac is x86_64 and shared objects were compiled on a x86_64. The compilation works on my Linux computer.

Here my Makefile:

CFLAGS = -std=c11 -Wall -Werror -Wextra -pedantic -I./include
LDLIBS = -L./lib64
LDFLAGS = -lSocketUDP -lAdresseInternet -lpthread

all: obj/tftp.o bin/server bin/client

obj/tftp.o: src/tftp.c
    mkdir -p obj
    $(CC) $(CFLAGS) -c $^ -o $@

bin/server: src/server.c obj/tftp.o
    mkdir -p bin
    $(CC) $(CFLAGS) $^ -o $@ $(LDLIBS) $(LDFLAGS)

bin/client: src/client.c obj/tftp.o
    mkdir -p bin
    $(CC) $(CFLAGS) $^ -o $@ $(LDLIBS) $(LDFLAGS)

clean:
    $(RM) -r obj

distclean:
    $(RM) -r obj bin

Thank you.

like image 471
mathieu_b Avatar asked Apr 18 '16 12:04

mathieu_b


2 Answers

You cannot do that as this "other x86_64 computer" was clearly running Linux and generating ELF-format object files.

0x7F 0x45 0x4C 0x46
0x7F 'E'  'L'  'F'

OSX/iOS uses Mach-O format object files and cannot be linked against different types of object file.

You will need to compile all the code under OSX.

like image 129
trojanfoe Avatar answered Sep 19 '22 12:09

trojanfoe


Your SocketUDP lib is probably built for Linux. Linux and OS X use different and incompatible object files, ELF vs . Mach-O.

You have to build the library on OS X as well.

like image 20
rems4e Avatar answered Sep 18 '22 12:09

rems4e