Boost library static linking on Xcode 4

Solutions Collect From Internet About “Boost library static linking on Xcode 4”

If you’ve linked with a .a library, then you have already linked statically. You never need to ship .a libraries. They’re just bundles of objects.


EDIT: Your error strongly suggests that you’re linking the dylib rather than the .a. If you have libfoo.dylib and libfoo.a in your library path, even if you say “link libfoo.a” in Xcode, and even if libfoo.a is earlier in the search path, it will still link libfoo.dylib. This is because Xcode’s linking is totally broken and passes -lfoo to the linker (you should never use -l for something you built and have the exact path to). I always recommend linking libraries you built in LDFLAGS in an xcconfig file rather than using the build pane. You pass the exact path you want rather than using -l. See Abandoning the Build Panel for more of my thoughts on xcconfig. It’s out of date now, since it was written for Xcode3, but the basics still apply.

Using the build pane, you can also pass the entire path to the library in “Other Linker Flags.” But this still has all the problems of the build pane.

The quicker (but less robust) solution is sometimes to add -Wl,-search_paths_first to the “Other Linker Flags.” This changes the behavior so that each library path is searched for both .dylib and .a before going on (the default behavior is to search everywhere for .dylib and only then search for .a). So if your .a is in a different directory from your .dylib, and that directory is earlier in the search path, this will work.

This question finally got me to open a radar on this, which I should have done years ago. I recommend that others open duplicates.