views:

1411

answers:

2

I'm trying to link to a static library on OS X. I used the -static flag in the gcc command but I an error message:

ld_classic: can't locate file for: -lcrt0.o
collect2: ld returned 1 exit status

I looked in the man pages and it reads something like:

This option will not work on Mac OS X unless all libraries (including libgcc.a) have also been compiled with -static. Since neither a static version of libSystem.dylib nor crt0.o are provided, this option is not useful to most people.

Is there another way to link to this static library?

A: 

In order to link to an archive library (sometimes also called static library), just add it to the link line:

gcc main.o ... -lfoo ...

The linker will search for libfoo.dylib, and then libfoo.a, which is all you need.

If you have both versions if the library, and want to link with an archive version in preference of the dynamic one, just specify full path to in on the link line:

gcc main.o ... /path/to/libfoo.a ...
Employed Russian
There's no crt0.o or crt0.a or anything like that on OS X and XCode.
alecco
+1  A: 

Regretfully, it's not supported. Some people reported it's possible to manually compile crt0 but nobody confirms it.

alecco