Force static linking of library linked to Xcode target?

Had this exact same problem and despite this being an old post, I thought I'd share what I had to do to make this work.

Usually you do just provide the switch '-static' to the linker however, with Xcode this causes all libs including the crt to be linked statically. I got the error:

can't locate file for: -lcrt0.o

When I tried above.

What worked for me was to replace:

-lmylib

With:

/path/to/libmylib.a

Note that the -l is dropped.


In reaction to your comment on Eduard Wirch' answer: you can also control static linking for this one library only, if you replace -lhdf5 by -l/full/path/to/libhdf5.a

Tags:

Gcc

Xcode

Linker