iPhone static library creation - iphone

I have created a static library LibA.a which includes some codes and another static library LibB.a. When I use this static library LibA.a in a new project I get many errors like these:
File1.h no such file or directory.
This file File1.h and others showing error are present in LibB.a.
Edit 1: I am using XCode 4.0.1
Edit 2: Now while creating my static library, I have made the header file public whose methods the user can use in their project. My static library references another static library named XWidget.a. I have added it into my static library's "Link Binary with Libraries" and also in the direct dependency. Then created my static library. Now I am testing my library in a demo project. In Header Search Paths of demo project I have added the path of my static library's public header file.When I run it, the header files which are present in the inner static library XWidget.a are not found. Giving errors like FileA.h: no such file or directory. Should I somehow provide the path of inner static library (XWidget.a) also? If yes then how? Or what else am I missing?

You need to include the header files in the project where you want to interface with the library.

Click on the big project button in Xcode's file management tab on the sidebar, select your target, click Build Phases, and pull down the drop down menu titled "Compile Sources". Then make sure all the necessary .m, not .h, files are there.
I've run into this problem a couple times myself, I hope this helps you!

Related

Static Library path nightmare from hell

This is the point. I have a subproject (static library) created. The library compiles well. No errors. When I include this library inside a project and imports a header from that library on the project the library fails to compile because it cannot find a path that belongs to itself.
After following a bunch of tutorials on the web on how to create a static library and embed that in a project, I don't know which one is the correct one, because I have tried all and all failed and some differ.
This is how the library is set:
STATIC LIBRARY
BUILD SETTINGS:
Public header folder path = $(BUILT_PRODUCTS_DIR)
Header search path = $(SRCROOT) (recursive)
BUILD PHASES
COPY FILES = 1 file, myLibrary.h that is basically empty (created by xcode when I used the static library template to start the library.
no ADD COPY HEADERS phase
MAIN PROJECT
BUILD SETTINGS
Header search path = empty
User header search path = $(BUILT_PRODUCTS_DIR) (recursive)
Always search user paths = YES
BUILD PHASES
Yes, myLibrary.a is on target dependencies
What amazes me is that the library compiles fine alone but when put inside a project, is unable to find a header that belongs to the own library.
NOTE: I have also tried to create a copy headers phase on the library making public all .h on that library, but it failed too.
This is an example of one error:
/Users/mike/Library/Developer/Xcode/DerivedData/MyApp-dnaimaovscreasadhmvgttwjnabc/Build/Products/Debug-iphoneos/include/myLibrary/ccTypes.h:39:9:
fatal error: 'Platforms/CCGL.h' file not found
#import "Platforms/CCGL.h"
I have lost two days trying to solve this nightmare.
any thoughts?
I have uploaded a sample project to here and here
After downloading your sample project, I had it working in a few minutes by making the following changes.
First, you need to add an entry for the MyProject target's Build Settings under Header Search Paths, so that the files such as HelloWorldLayer.h, which #import "cocos2d.h", know where to find that file.
Under the Header Search Paths, I entered ../MyStaticLibrary/MyStaticLibrary/libs/** like shown in the image below:
That solved the problem of the inability of the preprocessor to find the necessary source files from the MyStaticLibrary, for the MyProject project, but after compiling, I got an error about missing symbols. I needed to add the built libMyStaticLibrary.a to the Link Binary With Libraries step like shown in the image below:
After that, the project compiles fine.
(Not enough rep to post comment...)
Did you try specifically including the Platforms directory in the header search path? Presumably, Platforms is in the source directory, not in $(BUILT_PRODUCTS_DIR) so may not be searched in your current setting.
Regarding script to show you env variables, here's how I do it (open images at the new tab for better scaling):
Added dummy shell script
Observed its output at Log Navigator
As you can see, BUILT_PRODUCTS_DIR doesn't have any headers copied from the library. Either put headers there manually (strongly not recommended) or add search path to the location that you know the headers must be at:
Now as there were two headers cocos2d.h and MyStaticLibrary.h, cocos2d.h was successfully imported although it will have additional dependency.
The path ../MyStaticLibrary/build/$(BUILD_STYLE)-$(PLATFORM_NAME) will also (recursively) have public headers of the library.
After almost 5 days of a nightmare trying to solve that, I finally found this tutorial: http://www.youtube.com/watch?v=XUhLETxgcoE
This is the only solution that worked for me. The simplest and the best.
Thanks for every one trying to solve this.
Please try this…
step1: right click on the 'projectName.xcodeproj'(static library).Choose 'Get info' and copy the full path from(General->where)
step2: Paste full path to 'Header search paths' for your main project(Both Targets and Project )

How to import static cocos library headers to my project(ARC)?

I've static cocos2d library and want to include it into my ARC project. I made cocos2d static library because using it my ARC project...
My projects build but if I want to #import the headers autocomplete shows no option for my static library or cocos.h or something. It's my first try with static libraries.
My workflow:
Created static library using this tutorial:
http://www.learn-cocos2d.com/2012/04/enabling-arc-cocos2d-project-howto-stepbystep-tutorialguide/
I created new workspace
From finder I draged my main project and project with static library included
In main project in Build Phases I added my linked library
In scheme for main project I added my library to targets and checked all checkboxes (run,
build...)
What else I need to be done? Thanks for help.
UPDATE
I read somewhere I need also add Build Phase and Copy headers and add some to Public section. What headers I need to ad there? All cocos2d library or cocos2s.h and cocosdension.h? Or name of my lib??
Here is screenshot:
Check your header search paths in your app settings and see that it's pointing to your static library and headers location (and make it recursive too).
For this, go to to your project, then Build Settings and search for Header Search Paths. If the path to your headers is missing, then add it (if you work from more than one computer or it's a more-than-one-person project make sure that it's not an absolute path, but relative to the project)

How to build a static library of an existing project in objective-c (.a file)?

I want to make .a file means static library of my project which I have made. How can I achieve this. Please provide me the the best solution, tutorial or any other links.
Thanks in advance
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.
With xcode4.2, easiest way is to new project, iOS/Framework & Library, CocoaTouch Static Library, and add all you files existed.
Here is the easiest tutorial with which i have built a static library in iphone. After building a static library you will import a .a library file and the header file .h in your new project and use them. Here is the tutorial link for making static library.

How to add statically created library in My application..?

I have created static library for testing.
I have used:
http://blog.boreal-kiss.net/2011/03/15/how-to-create-universal-static-libraries-on-xcode-4/#identifier_0_432
Its created sucessfully as test.a now i want to add this library in my application.
can anybody help me out for this?
Open Xcode.
Click on project file (the first item in Project navigator)
Select one of appropriate target
Open Build Phases
Select Link Binary With Libraries
Add your library
check this link
http://www.amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html
and go for Link binary, Direct dependency this will refer you static library to your xcode project .

importing private frameworks in Xcode

I am a novice iPhone programmer I want to use some of the functions in the private framework
https://github.com/kennytm/iphone-private-frameworks
The function that I want to use is in 'SpringBoard'
So I downloaded 'SpringBoard' folder in that github repo.
And created a subdirectory called "Headers" in 'SpringBoard'
and put all the header files in that folder.
And renamed 'SpringBoard' to 'SpringBoard.framework' and copied it to /Developer/Platforms/(iPhoneOS_and_iPhoneSimulator)/sdks/System/library/Frameworks folder (I can't recall full path correctly sorry)
And I got back to the xcode and right click on Frameworks -> Add existing framework -> other -> I selected 'SpringBoard.framework' folder and clicked Add.
And I built the project and got an error
'ld : framework SpringBoard not found'
My imported framework does appear on the Xcode and I can see header files in it.
but when I built it I got that error.
What am I doing wrong?
Place all of your private headers in a directory like: /User/Name/Headers/ then set USER_HEADER_SEARCH_PATHS = "/User/Name/Headers/" and make sure that ALWAYS_SEARCH_USER_PATHS = YES
Also, SpringBoard.framework is not the way to do that.Simply place the folder named SpringBoard in the above Headers folder, making sure that the headers are directly inside them. For instance: SpringBoard/SBAlert.h
/* SpringBoard is not a framework. */
Notice that you wont have to add the SpringBoard folder to your project, they should appear as you start typing, as long as you set the above headers correctly.
I'm not sure if this works, but here a suggestion:
I think the spring board framework should be in the UIKit framework you already linked anyway, so just add the header file to your project and it should work.
Otherwise this could help you:
http://www.codethecode.com/projects/class-dump/