tags:

views:

118

answers:

1

I have an object file, which I'd like to make into a Mach-O binary(I'm on Mac OS 10.6). Running ld -e _main source.o /usr/lib/libc.dylib produces the following output:

ld: symbol dyld_stub_binding_helper not defined (usually in crt1.o/dylib1.o/bundle1.o) for inferred architecture x86_64

How can I reference libc using ld?

+2  A: 

You'll need to add to the ld invocation the libraries that your object file calls to -- in static or dynamic form. For printf, in particular, I think you want /usr/lib/libc.dylib.

Alex Martelli
If I do `ld -e _main source.o /usr/lib/libc.dylib `, I get `ld: symbol dyld_stub_binding_helper not defined (usually in crt1.o/dylib1.o/bundle1.o) for inferred architecture x86_64`.
Mike
@Mike, so you also need `/usr/lib/crt1.o` in your `ld` command line.
Alex Martelli
The linking worked, but I'm getting a segfault:Program received signal EXC_BAD_ACCESS, Could not access memory.Reason: 13 at address: 0x00000000000000000x00007fff5fc0ff75 in __dyld_stub_binding_helper_interface ()
Mike
@Mike, sorry, I'm out of ideas (I don't know what else is missing in terms of `ld` options or arguments).
Alex Martelli
Found the issue - I was specifying my own entry point, which prohibited the libc initializers from running. Taking out the -e arg solved the problem!
Mike
@Mike, oh good! Hadn't noticed the `-e` in your comment...
Alex Martelli