Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Xcode automatically link against the libraries needed by objects in static library

I have a xcode project with a target that builds a ‘Cocoa Touch Static Library’, the user can successfully depend on this project from her app project and link against the library.

However, some of the objects in the archive depend on other libraries, so the user has to add these to the app project herself. Is there a way with Xcode to eliminate this step? I.e. can I specify in the library’s project on which libraries it depends which are then automatically linked in to the app? (In the library project, or as a xcconfig file, or whatever works.)

like image 368
alloy Avatar asked Sep 12 '11 11:09

alloy


People also ask

Where is linked frameworks and libraries in Xcode?

If you're building for iOS, tvOS, or watchOS: On your application targets' “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

What is Xcode static library?

Static library: A unit of code linked at compile-time, which does not change. (Can only contain code). The code that the app uses is copied to the generated executable file by a static linker during compilation time. However, iOS static libraries are not allowed to contain images/assets (only code).

Does swift support static libraries?

Question: Can we create static frameworks using Swift? Answer: Finally, YES! (Xcode 9). CocoaPods announced the support of Swift Static Frameworks in 1.5.


1 Answers

I’ve ended up going with a xcconfig that the user's app target configurations are based on. This xcconfig contains:

USER_HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)
ALWAYS_SEARCH_USER_PATHS = YES
OTHER_LDFLAGS = -framework SystemConfiguration -framework CFNetwork -framework MobileCoreServices -l z.1.2.3 -l xml2.2.7.3
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"

This together with the library in a workspace together with the app makes it all work.

like image 200
alloy Avatar answered Oct 16 '22 07:10

alloy