C++ use a linux library on a mac (elf64-x86-64 on x86_64-apple-darwin)

0

I'm currently trying to compile a program on a Mac OS X (10.9) using a library initially compiled for Linux.

Is there a way to use this library? Here is the output of objdump -f libmylib.a:

Hour.o:       file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000


Menu.o:       file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000


Tools.o:      file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000

I know my current architecture is x86_64-apple-darwin13.0.0, and I wonder if, with the appropriate compiler flags, there is a way to make this compile.

One more thing, here is the error when trying to compile:

g++  -L /Users/gustavemonod/Desktop/ -o Parking Mother.o Keyboard.o -lncurses -ltcl -lmylib
ld: warning: ignoring file /Users/gustavemonod/lib/libmylib.a, file was built for archive which is not the architecture being linked (x86_64): /Users/gustavemonod/lib/libmylib.a
c++
x86-64
elf
asked on Stack Overflow Feb 19, 2014 by Gus Monod

2 Answers

0

Linux uses a library format called ELF. Mac does not use ELF (instead, Mac uses a format called Mach-O), so I suspect that's going to be very difficult (if not actually impossible). You might be able to make the Linux Binary Compatibility from FreeBSD work.

answered on Stack Overflow Feb 19, 2014 by Elliott Frisch
0

You cannot link ELF objects (or archives or shared libraries) with Mach-O. You can try using Agner Fog's objconv utility, to convert x86-64 ELF to x86-64 Mach-O, which use the same (ELF) calling conventions. I wouldn't recommend this approach if you can compile from source.

answered on Stack Overflow Feb 19, 2014 by Brett Hale

User contributions licensed under CC BY-SA 3.0