Boost library static linking on Xcode 4
I am using the Boost library on OS X using Xcode. Boost was installed on my system using macports. I have successfully built my app by adding the 3 boost libraries I need (for example, libboost_thread-mt.a) to that Targets ‘Link Binary With Libraries’ list. However I need to link these libraries statically so that the app will run on other computers without the boost library needing to be installed.
How do I do this exactly? Through my numerous google searches I’m finding I might need to add ‘-static’ – where do I add this in Xcode?
- How can I compile Boost 1.54.0 (1.54) for the iOS simulator (6.1) on OS X 10.8.4?
- xcode with boost : linker(Id) Warning about visibility settings
- 'openssl/conf.h' file not found error on MacOS Sierra
- Yet another “ld: symbol(s) not found for architecture x86_64” issue with boost, this time with mgiza
- Boost Xcode C++ command line Undefined symbols for architecture x86_64
- XCode with boost “Semantic Issue - undeclared identifier va_start”
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.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
.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.
- Adding Convenience Initializers in Swift Subclass
- How do I make my App run an NSTimer in the background?
- NSTimer not firing when NSMenu is open in Swift
- touchesBegan, touchesEnded, touchesMoved for moving UIView
- Erasing after drawing with CGContext
- Changing the size of UITableView programmatically
- Swift 3 How to validate server certificate using SSL Pinning and AlamoFire?
- Xcode 7: changing product bundle identifier
- Realm database object seems empty, but then isn't
- Force a WebView link to launch Safari?
- How to properly develop for the iPhone on a PowerPC Mac?
- Does Swift use message dispatch for methods?
- Swift iOS -UIImagePicker's Photo Library Is Presented On Simulator But Crashes (won't present) On Actual Device While Running Xcode
- Animating an image view to slide upwards
- iOS 11 beta 4 presentRenderbuffer crash