How to build a static library of an existing project in objective-c (.a file)?
http://mobileorchard.com/sharing-compiled-code-building-static-libraries-in-xcode-for-the-iphone/ has a good tutorial.
Here are the basic steps:
- Understand that XIB/NIB/Storyboard files have to be included separately from the library
- Add a new target that is a static library
- In the build settings for that library, include all of the .h and .m files that are relevant. For example, if your app uses a set of classes to access data and another set to view that data, you may want to just include the files relevant to accessing data.
- Build. Use the script provided at Build fat static library (device + simulator) using Xcode and SDK 4+ so that you can use it for iPhone simulator + device.
- Include your library + headers + any resources in relevant project.
Import a static library as a subproject
You must add Header Search Path
to your target. In build setting search "Header Search Path" and add relative link to your static library project. How to add relative path read more here
You may need to search path with recursive
option.
Any way to make bundle xcode project to include a static library xcode project?
Finally, I make it work.
The step 10 still important and below is corrected step 10.
- create a dummy.c under (.bundle) project and the dummy.c can just totally empty. remove the setting for the library you want to link inside
Link Binary With Libraries
instead use-Wl,-force_load,$(CONFIGURATION_BUILD_DIR)/libYourLib.a
or-all_load
toOther Linker Flags
PS: And also can use sub-project instead of workspace. and use Target Dependencies
instead of Edit Scheme
to achieve the same effect.
The testing project
add static library to xcode project from command line
Not a directly command line way, but you can write a ruby script to do the trick. You can use a gem called xcodeproj
to edit the Xcode project file.
For adding a .a library, you may want to create an Project
object with the path of your project file, then use the new_file
method of the Project
class to add it to the project. It is equivalent to dragging the same file to Xcode. For the header file, you can either add them as new file to the project (the same as the library) or just set the HEADER_SEARCH_PATHS
key of the Xcodeproj::Project::Object::XCBuildConfiguration
of the project object.
For more information and usage of xcodeproj, you can refer to the home page and the doc page.
Linking a static library to an iOS project in Xcode 4
I do this as follows:
- Drag in the static library project. If you have the static library project open in Xcode, close it now.
- Select the main project in the project navigator (the project I'm adding the static library to) and in the editor, under the header TARGETS in the left-hand column, select my main project's target and navigate to the Build Phases tab.
- Click the "+" for Target Dependencies and add the library icon target dependency from the added static library project.
- Click the "+" for Link Binary with Libraries and add the library icon that is under the folder "Workspace".
- It may also be necessary to enter a Header Search Path for the headers of the static library project if that is how the headers are linked in the static library project itself.
If you don't see the static library project as nested under the main project in the main project's project navigator, the most likely reason for that is that the static library's own Xcode project is still open. Quit Xcode and open up the main project that has the nested static library project in it without opening up the original static library project itself, and you should see it appearing as a nested project in your main project.
Related Topics
iOS Nsattributedstring on Uibutton
Exc_Bad_Instruction (Code=Exc_I386_Invop, Subcode=0X0) on Dispatch_Semaphore_Dispose
Could Not Find Module for Target 'X86_64-Apple-Ios-Simulator'
Xcode 5.1: Libcordova.A Architecture Problems
How to Remove the Authorization Prompt from Command-Line Instances of Instruments (Xcode)
Uiview Touch Event in Controller
Facebook Graph API Get Request - Should Contain "Fields" Parameter (Swift, Facebook Sdk V4.5.1)
How to Add a Button to Uinavigationbar
Modify Uiimage Renderingmode from a Storyboard/Xib File
Why Is My iOS App Not Showing Up in Other Apps' "Open In" Dialog
Steps to Create and Edit a Plist File in Xcode
Cookie Sharing Between Multiple Wkwebviews
How to Get Back "Allow Push Notifications" Dialog After It Was Dismissed Once
Could Not Launch Process Launch Failed: Timed Out Waiting for App to Launch
How to Get a Transparent Background in My iOS App So I Can See the Home Screen Wallpaper
"No Such Module 'Alamofire'" Xcode Won't Recognize Alamofire Framework