Code Script 🚀

Build fat static library device simulator using Xcode and SDK 4

February 15, 2025

đź“‚ Categories: Programming
🏷 Tags: Iphone Xcode
Build fat static library device  simulator using Xcode and SDK 4

Creating iOS static libraries, particularly “abdominous” libraries that activity some instrumentality and simulator architectures, is a communal project for builders wanting to stock codification, make modular initiatives, oregon administer SDKs. Piece Xcode affords constructed-successful activity for gathering libraries, the procedure of creating a cosmopolitan oregon “abdominous” room requires any other steps. This article explores the intricacies of gathering these libraries utilizing Xcode and SDK four+ and offers applicable methods for seamless integration into your iOS improvement workflow. Knowing this procedure is important for immoderate iOS developer aiming for businesslike codification direction and organisation.

Knowing Static Libraries successful iOS Improvement

Static libraries are archives of compiled codification, linked with your exertion throughout the physique procedure. They message respective benefits, together with modularity, codification reuse, and diminished compilation occasions. Dissimilar dynamic libraries loaded astatine runtime, static libraries go portion of your exertion’s executable record. This makes organisation less complicated however tin somewhat addition the exertion’s dimension. Selecting betwixt static and dynamic libraries relies upon connected your task’s circumstantial wants and priorities.

For case, ideate gathering an SDK for representation processing. Packaging the center representation manipulation algorithms into a static room lets you easy stock this performance crossed aggregate apps with out exposing the origin codification. This modular attack streamlines improvement and simplifies care.

The Demand for Abdominous Static Libraries

iOS units and simulators usage antithetic architectures (arm64, armv7, x86_64, i386). A modular static room constructed for 1 structure received’t activity connected different. A “abdominous” room combines aggregate architectures into a azygous record, enabling compatibility crossed some instrumentality and simulator. This simplifies improvement and investigating by permitting you to physique and tally your codification with out switching betwixt antithetic room variations.

See a script wherever you’re processing an app that makes use of a 3rd-organization room for web connection. If this room is supplied arsenic a abdominous static room, you tin seamlessly combine it into your task and trial it connected some the simulator and a animal instrumentality with out immoderate structure-associated conflicts.

Gathering a Abdominous Static Room with Xcode

Creating a abdominous static room entails gathering abstracted libraries for all structure and past combining them. Present’s a measure-by-measure procedure:

  1. Make a fresh Xcode task and choice “Static Room” arsenic the template.
  2. Configure your physique settings to mark aggregate architectures (arm64, armv7 for gadgets, x86_64, i386 for simulators). You tin negociate this inside the “Architectures” and “Legitimate Architectures” settings inside your task’s physique settings.
  3. Physique the room for all structure individually. Xcode gives choices for gathering for antithetic locations.
  4. Usage the lipo bid-formation implement to harvester the idiosyncratic structure-circumstantial libraries into a azygous abdominous room. For illustration: lipo -make -output libMyLibrary.a libMyLibrary-instrumentality.a libMyLibrary-simulator.a

This procedure creates a cosmopolitan room record (libMyLibrary.a successful this illustration) that you tin past combine into your iOS initiatives.

Integrating the Abdominous Static Room into Your Task

Erstwhile you person the abdominous room, integrating it into your task is easy:

  • Resistance the .a record into your task.
  • Successful your task’s physique settings, nexus the room nether “Nexus Binary With Libraries.”
  • Import the essential headers successful your codification records-data.

Guarantee your task settings appropriately see the room hunt paths and linked frameworks to debar physique errors.

For additional speechmaking connected linking libraries and managing dependencies, mention to Pome’s authoritative documentation: Creating Frameworks

Troubleshooting Communal Points

Generally, you mightiness brush points similar “Undefined symbols for structure i386” oregon akin errors. These normally originate from structure mismatches oregon lacking dependencies. Cautiously reappraisal your physique settings, guarantee each required architectures are included successful your abdominous room, and treble-cheque that each babelike libraries are besides accurately linked.

Champion Practices for Static Room Direction

For optimum direction of your static libraries, see utilizing a dependency director similar CocoaPods oregon Carthage. These instruments automate the procedure of integrating and updating outer libraries, importantly simplifying your workflow. They besides grip resolving dependencies and guarantee appropriate configuration, decreasing the hazard of physique errors. Larn much astir dependency direction.

Gathering and utilizing abdominous static libraries tin streamline your iOS improvement procedure. By knowing the underlying ideas and pursuing champion practices, you tin efficaciously negociate dependencies, better codification reusability, and simplify organisation. This blanket attack enhances some ratio and task maintainability.

[Infographic illustrating the procedure of creating and integrating a abdominous static room]

Often Requested Questions

Q: What’s the quality betwixt a static room and a model?

A: Piece some incorporate reusable codification, frameworks bundle assets (photographs, nib information, and so on.) on with the compiled codification, offering a much same-contained and modular part. Static libraries mostly lone incorporate compiled codification. Successful status of linking, some tin beryllium statically oregon dynamically linked. Larn Much connected Stack Overflow

This attack, piece requiring a spot much setup, significantly simplifies improvement and investigating by permitting you to activity seamlessly crossed antithetic iOS environments. By leveraging Xcode’s capabilities and incorporating champion practices for room direction, you tin physique strong and maintainable functions.

Different adjuvant assets mightiness springiness you much penetration. Research these strategies and optimize your iOS improvement workflow present! Question & Answer :
It seems that we tin - theoretically - physique a azygous static room that contains some simulator and iPhone and iPad.

Nevertheless, Pome has nary documentation connected this that I tin discovery, and Xcode’s default templates are NOT configured to bash this.

I’m wanting for a elemental, transportable, re-usable method that tin beryllium accomplished wrong Xcode.

Any past:

  • Successful 2008, we utilized to beryllium capable to brand azygous static-libs that included some sim and instrumentality. Pome disabled that.
  • Passim 2009, we made pairs of static libs - 1 for sim, 1 for instrumentality. Pome has present disabled that excessively.

References:

  1. This is a large thought, it’s an fantabulous attack, however it doesn’t activity: http://www.drobnik.com/contact/2010/04/cosmopolitan-static-libraries/

    • Location’s any bugs successful his book that means it lone plant connected his device - helium ought to beryllium utilizing BUILT_PRODUCTS_DIR and/oregon BUILD_DIR alternatively of “guesstimating” them)
    • Pome’s newest Xcode prevents you from doing what helium’s carried out - it merely volition not activity, owed to the (Documented) alteration successful however Xcode processes targets)
  2. Different Truthful questioner requested however to bash it With out xcode, and with responses that focussed connected the arm6 vs arm7 portion - however ignored the i386 portion: However bash i compile a static room (abdominous) for armv6, armv7 and i386

    • Since Pome’s newest modifications, the Simulator portion isn’t the aforesaid arsenic the arm6/arm7 quality immoderate much - it’s a antithetic job, seat supra)

Alternate options:

Casual transcript/paste of newest interpretation (however instal directions whitethorn alteration - seat beneath!)

Karl’s room takes overmuch much attempt to setup, however overmuch nicer agelong-word resolution (it converts your room into a Model).

Usage this, past tweak it to adhd activity for Archive builds - c.f. @Frederik’s remark beneath connected the modifications helium’s utilizing to brand this activity properly with Archive manner.


New Adjustments: 1. Added activity for iOS 10.x (piece sustaining activity for older platforms)

  1. Data connected however to usage this book with a task-embedded-successful-different-task (though I extremely urge NOT doing that, always - Pome has a mates of entertainment-stopper bugs successful Xcode if you embed initiatives wrong all another, from Xcode three.x done to Xcode four.6.x)
  2. Bonus book to fto you car-see Bundles (i.e. see PNG records-data, PLIST information and so forth from your room!) - seat beneath (scroll to bottommost)
  3. present helps iPhone5 (utilizing Pome’s workaround to the bugs successful lipo). Line: the instal directions person modified (I tin most likely simplify this by altering the book successful early, however don’t privation to hazard it present)
  4. “transcript headers” conception present respects the physique mounting for the determination of the national headers (courtesy of Frederik Wallner)
  5. Added specific mounting of SYMROOT (possibly demand OBJROOT to beryllium fit excessively?), acknowledgment to Doug Dickinson

Book (this is what you person to transcript/paste)

For utilization / instal directions, seat beneath

########################################## # # c.f. https://stackoverflow.com/questions/3520977/physique-abdominous-static-room-instrumentality-simulator-utilizing-xcode-and-sdk-four # # Interpretation 2.eighty two # # Newest Alteration: # - Much tweaks to acquire the iOS 10+ and 9- running # - Activity iOS 10+ # - Corrected typo for iOS 1-10+ (acknowledgment @stuikomma) # # Intent: # Routinely make a Cosmopolitan static room for iPhone + iPad + iPhone Simulator from inside XCode # # Writer: Adam Martin - http://twitter.com/redglassesapps # Based mostly connected: first book from Eonil (chief adjustments: Eonil's book Volition NOT Activity successful Xcode GUI - it Volition Clang YOUR Machine) # fit -e fit -o pipefail #################[ Exams: helps workaround immoderate early bugs successful Xcode ]######## # DEBUG_THIS_SCRIPT="mendacious" if [ $DEBUG_THIS_SCRIPT = "actual" ] past echo "########### Checks #############" echo "Usage the pursuing variables once debugging this book; line that they whitethorn alteration connected recursions" echo "BUILD_DIR = $BUILD_DIR" echo "BUILD_ROOT = $BUILD_ROOT" echo "CONFIGURATION_BUILD_DIR = $CONFIGURATION_BUILD_DIR" echo "BUILT_PRODUCTS_DIR = $BUILT_PRODUCTS_DIR" echo "CONFIGURATION_TEMP_DIR = $CONFIGURATION_TEMP_DIR" echo "TARGET_BUILD_DIR = $TARGET_BUILD_DIR" fi #####################[ portion 1 ]################## # Archetypal, activity retired the BASESDK interpretation figure (NB: Pome ought to study this, however they fell it) # (incidental: looking for substrings successful sh is a nightmare! Sob) SDK_VERSION=$(echo ${SDK_NAME} | grep -o '\d\{1,2\}\.\d\{1,2\}$') # Adjacent, activity retired if we're successful SIM oregon Instrumentality if [ ${PLATFORM_NAME} = "iphonesimulator" ] past OTHER_SDK_TO_BUILD=iphoneos${SDK_VERSION} other OTHER_SDK_TO_BUILD=iphonesimulator${SDK_VERSION} fi echo "XCode has chosen SDK: ${PLATFORM_NAME} with interpretation: ${SDK_VERSION} (though backmost-targetting: ${IPHONEOS_DEPLOYMENT_TARGET})" echo "...so, OTHER_SDK_TO_BUILD = ${OTHER_SDK_TO_BUILD}" # #####################[ extremity of portion 1 ]################## #####################[ portion 2 ]################## # # IF this is the first invocation, invoke Any another builds are required # # Xcode is already gathering 1 mark... # # ...however this is a Room, truthful Pome is incorrect to fit it to physique conscionable 1. # ...we demand to physique Each targets # ...we Essential NOT re-physique the mark that is ALREADY being constructed: Xcode Volition Clang YOUR Machine if you attempt this (infinite recursion!) # # # Truthful: physique Lone the lacking platforms/configurations. if [ "actual" == ${ALREADYINVOKED:-mendacious} ] past echo "RECURSION: I americium NOT the base invocation, truthful I'm NOT going to recurse" other # Captious: # Forestall infinite recursion (Xcode sucks) export ALREADYINVOKED="actual" echo "RECURSION: I americium the base ... recursing each lacking physique targets Present..." echo "RECURSION: ...astir to invoke: xcodebuild -configuration \"${CONFIGURATION}\" -task \"${PROJECT_NAME}.xcodeproj\" -mark \"${TARGET_NAME}\" -sdk \"${OTHER_SDK_TO_BUILD}\" ${Act} RUN_CLANG_STATIC_ANALYZER=Nary" BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" SYMROOT=\"${SYMROOT}\" xcodebuild -configuration "${CONFIGURATION}" -task "${PROJECT_NAME}.xcodeproj" -mark "${TARGET_NAME}" -sdk "${OTHER_SDK_TO_BUILD}" ${Act} RUN_CLANG_STATIC_ANALYZER=Nary BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" Act="physique" #Merge each level binaries arsenic a abdominous binary for all configurations. # Cipher wherever the (aggregate) constructed records-data are coming from: CURRENTCONFIG_DEVICE_DIR=${SYMROOT}/${CONFIGURATION}-iphoneos CURRENTCONFIG_SIMULATOR_DIR=${SYMROOT}/${CONFIGURATION}-iphonesimulator echo "Taking instrumentality physique from: ${CURRENTCONFIG_DEVICE_DIR}" echo "Taking simulator physique from: ${CURRENTCONFIG_SIMULATOR_DIR}" CREATING_UNIVERSAL_DIR=${SYMROOT}/${CONFIGURATION}-cosmopolitan echo "...I volition output a cosmopolitan physique to: ${CREATING_UNIVERSAL_DIR}" # ... distance the merchandise of former runs of this book # NB: this listing is Lone created by this book - it ought to beryllium harmless to delete! rm -rf "${CREATING_UNIVERSAL_DIR}" mkdir "${CREATING_UNIVERSAL_DIR}" # echo "lipo: for actual configuration (${CONFIGURATION}) creating output record: ${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}" xcrun -sdk iphoneos lipo -make -output "${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}" "${CURRENTCONFIG_DEVICE_DIR}/${EXECUTABLE_NAME}" "${CURRENTCONFIG_SIMULATOR_DIR}/${EXECUTABLE_NAME}" ######### # # Added: StackOverflow proposition to besides transcript "see" records-data # (untested, however ought to activity Fine) # echo "Fetching headers from ${PUBLIC_HEADERS_FOLDER_PATH}" echo " (if you embed your room task successful different task, you volition demand to adhd" echo " a "Person Hunt Headers" physique mounting of: (NB See THE Treble QUOTES Beneath!)" echo ' "$(TARGET_BUILD_DIR)/usr/section/see/"' if [ -d "${CURRENTCONFIG_DEVICE_DIR}${PUBLIC_HEADERS_FOLDER_PATH}" ] past mkdir -p "${CREATING_UNIVERSAL_DIR}${PUBLIC_HEADERS_FOLDER_PATH}" # * wants to beryllium extracurricular the treble quotes? cp -r "${CURRENTCONFIG_DEVICE_DIR}${PUBLIC_HEADERS_FOLDER_PATH}"* "${CREATING_UNIVERSAL_DIR}${PUBLIC_HEADERS_FOLDER_PATH}" fi fi 

Instal Directions

  1. Make a static lib task
  2. Choice the Mark
  3. Successful “Physique Settings” tab, fit “Physique Progressive Structure Lone” to “Nary” (for each gadgets)
  4. Successful “Physique Phases” tab, choice “Adhd … Fresh Physique Form … Fresh Tally Book Physique Form”
  5. Transcript/paste the book (supra) into the container

…BONUS Non-compulsory utilization:

  1. Non-compulsory: if you person headers successful your room, adhd them to the “Transcript Headers” form
  2. Non-compulsory: …and resistance/driblet them from the “Task” conception to the “National” conception
  3. Non-compulsory: …and they volition Mechanically beryllium exported all clip you physique the app, into a sub-listing of the “debug-cosmopolitan” listing (they volition beryllium successful usr/section/see)
  4. Optionally available: Line: if you besides attempt to resistance/driblet your task into different Xcode task, this exposes a bug successful Xcode four, wherever it can’t make an .IPA record if you person National Headers successful your resistance/dropped task. The workaround: dont’ embed xcode tasks (excessively galore bugs successful Pome’s codification!)

If you tin’t discovery the output record, present’s a workaround:

  1. Adhd the pursuing codification to the precise extremity of the book (courtesy of Frederik Wallner): unfastened “${CREATING_UNIVERSAL_DIR}”

  2. Pome deletes each output last 200 traces. Choice your Mark, and successful the Tally Book Form, you Essential untick: “Entertainment situation variables successful physique log”

  3. if you’re utilizing a customized “physique output” listing for XCode4, past XCode places each your “surprising” records-data successful the incorrect spot.

    1. Physique the task
    2. Click on connected the past icon connected the correct, successful the apical near country of Xcode4.
    3. Choice the apical point (this is your “about new physique”. Pome ought to car-choice it, however they didn’t deliberation of that)
    4. successful the chief framework, scroll to bottommost. The precise past formation ought to publication: lipo: for actual configuration (Debug) creating output record: /Customers/blah/Room/Developer/Xcode/DerivedData/AppName-ashwnbutvodmoleijzlncudsekyf/Physique/Merchandise/Debug-cosmopolitan/libTargetName.a

    …that is the determination of your Cosmopolitan Physique.


However to see “non sourcecode” information successful your task (PNG, PLIST, XML, and many others)

  1. Bash the whole lot supra, cheque it plant
  2. Make a fresh Tally Book form that comes Last THE Archetypal 1 (transcript/paste the codification beneath)
  3. Make a fresh Mark successful Xcode, of kind “bundle”
  4. Successful your Chief Task, successful “Physique Phases”, adhd the fresh bundle arsenic thing it “relies upon connected” (apical conception, deed the positive fastener, scroll to bottommost, discovery the “.bundle” record successful your Merchandise)
  5. Successful your Fresh BUNDLE Mark, successful “Physique Phases”, adhd a “Transcript Bundle Sources” conception, and resistance/driblet each the PNG records-data and many others into it

Book to car-transcript the constructed bundle(s) into aforesaid folder arsenic your Abdominous static room:

echo "RunScript2:" echo "Autocopying immoderate bundles into the 'cosmopolitan' output folder created by RunScript1" CREATING_UNIVERSAL_DIR=${SYMROOT}/${CONFIGURATION}-cosmopolitan cp -r "${BUILT_PRODUCTS_DIR}/"*.bundle "${CREATING_UNIVERSAL_DIR}"