iPhone static library linking problem - iphone

I having trouble with app that uses my static libs. Here is my setup:
I have 3 libs, Utilities, Share and Misc. Share and Misc depend on Utilities. They are compiling just fine when I compile them separately. Every lib is in its own XCode project.
I want to build an app that uses features from Utilities and Share, so I added them into the project as direct dependencies. I see them listed in target "Link binary with libraries". I also see quite a lot of linking errors in the compilation results. Those error relate to 3rd parties code that is used in libraries, for example ASIHTTPRequest. Such 3rd party stuff I keep in one place and I just added path to that directory in "Header Search Paths".
Example error:
objc-class-ref-to-ASIHTTPRequest in libShare.a(SomethingThatIsInLib.o)
It's confusing because libs alone are compiling just fine but when I try to compile the app, it's throwing such errors. What am I doing wrong?

Add the -all_load and -ObjC flags to "Other Linker Flags" in the Xcode project settings.

Related

confusion in Header search path for adding static library in xcode 4.x?

I am getting confused in adding core plot static library in xcode 4.5. it is different from xcode 3.x versions. I tried many things, it gave header file not found and linker errors.
I have followed the steps as follows. In which situation we have to use recursive in Header search path. If any has done wrongly, please help?
1)Adding coreplot library and its headers in Xcode project.(ticked
for copy locally)
2)converted compiler to LLVM GCC 4.2 in project build settings.(not in
target build setting)
3)Compiler for thumb will be "NO"
4)Added Header Search Path in project build settings as ,with
recursive
"$(SRCROOT)/Libs/CorePlot/CorePlotHeaders"
5)Added Header Search Path in target build settings as
$(inherited)
6)Library search path will be as empty in both target and project
build settings.
7)-ObjC was added in Other linker flag in target build
settings.Removed -all_load from it.
8)Always search path will be YES in both target and project build
settings.
9)Build archive architecture only will be YES.
I had same issues a couple a days ago when trying to add CorePlot this way but I found out that there is a far easier process :
Copy the CorePlotHeaders directory to your Xcode project
Copy the Core Plot library to your Xcode project.
Open your apps Target Build Settings, and for Other Linker Flags include this:
-ObjC (-all_load used to be required as a linker flag, but this is no longer needed in Xcode 4.2)
Add the QuartzCore framework to the project.
Change your C/C++ Compiler in the project build settings to LLVM GCC 4.2 or LLVM 1.6.
In my case, i did not need to change my C/C++ Compiler to make CorePlot working

Not able to add Omnigroup framework for rtf editor in a my iPad application

I have been trying to add omnigroup framework for editing rtf files into my local iPad application. But always I am getting the errors like OmniBase/OmniBase.h, OmniFoundation/OmniFoundation.h files are not found.
I tried with different combinations of settings in the build settings of project target. But did not work. I am using Xcode version 4.2.1,
Mac OS X : 10.7 and IOS 5 Lion OS.
There's actually a lot of Xcode configuration involved in using the Omni frameworks. I recently went through the learning process myself and wrote a lengthy tutorial. My tutorial is centered around using OUIEditableFrame but it should be a good starting point for whatever part of the framework you're looking to use.
In a nutshell:
Make sure you're including Omni's Configuration directory in your project.
Add the required frameworks by adding the appropriate .xcodeproj files from Omni to your project. Many frameworks are dependent on other so all dependencies will need to be added.
Add required libraries to the Link Binary with Libraries section of the Build Phases tab.
Add required libraries to the Target Dependencies section of the Build Phases tab.
Edit your Schema. Select Build and add the required libraries.

iphone - ".../libtool: can't locate file for: -lxml2"

I have a 2 projects in an xcode workspace. One is a static library and the other one use the static library.
In the static library I added the GDataXMLNode.h and GDataXMLNode.m files, which I use in the main project. The GDataXMLNode.h is a public file so it's visible in the main project. I also linked the target of both projects with libxml2.dylib. And I also include in the Header Search Paths and User Header Search Paths the location /usr/include/libxml2.
Although these, I get an Apple Mach-O Librarian Error:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: can't locate file for: -lxml2
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: -lxml2 is not an object file (not allowed in a library)
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libxml2.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libxml2.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool failed with exit code 1
Do you know how can I fix this?
I had the exact same error recently. As you found, removing "-lxml2" from the "Other Linker Flags" in Build Settings helped resolve the errors. This is true when you are building a static library. You will need to include that linker flag ("-lxml2") in any target that actually includes your static library. For example, if you created unit tests for your static library as I did (i.e. MyStaticLibraryProjectTests) then you would need to make sure to add the linker flags to the MyStaticLibraryProjectTests target but not to the actual MyStaticLibraryProject target. More often than not I generally forget to select a specific target when I go to look at my Build Settings tab. I usually assume that if I click on the big blue project icon that the build settings are just for the entire project but it is very important to select the correct target when modifying those settings.
Early on most projects generally do only have a single target but as you get more advanced it is possible to have multiple targets for each project. Hope that helps.

Xcode - deleted openFrameworks libraries, now can't compile and having trouble re-adding

I was 'cleaning up' a project and deleted some of the references to libs used with openFrameworks. Certain things weren't being used, or so I mistakenly thought... Panic in my project!
All sorts of errors, of course. But, XCode won't let me undo that sort of action. I've re-added the libs but the errors persist. Can someone explain to me what basic conceptual thing I'm missing?
Errors go like this [edited]:
/Developer/openFrameworks-iPhone/libs/openFrameworks/app/ofAppGlutWindow.cpp:61: error: 'glutInit' was not declared in this scope
/Developer/openFrameworks-iPhone/libs/openFrameworks/app/ofAppGlutWindow.cpp:62: error: 'GLUT_RGB' was not declared in this scope
/Developer/openFrameworks-iPhone/libs/openFrameworks/app/ofAppGlutWindow.cpp:62: error: 'GLUT_DOUBLE' was not declared in this scope
[UPDATE]. Two things to check: (1) Having a valid build of the oF library itself. Open library project, make sure it builds.
(2) Is the oF library (and all the other, dependent libraries such as Poco) being added in the Build Phases > Link Binary With Libraries section? Sometimes when you delete and then re-add a library, it doesn't get included on this list. Re-drag the library files here. That's what ultimately solved this for me.
Have you tried clean build? I got this error once when adding static libraries.
Found it: Had to manually add the appropriate libraries to be included under "Build Phases". Built the clean download of openFrameworks that way; afterward I could add that to projects referencing the library and build them!

How to build universal static library that works for os3.x and os4.x

Hi I'm trying to create a static library that can added to any ios project, but I can only get it to work such that if I build the library in ios3, it'll work for ios3 projects but not ios4 and vice versa.
The errors I get are:
Undefined symbols:
".objc_class_name_UIImage", referenced from:
literal-pointer#_OBJC#_cls_refs#UIImage in Test3-Release.a(TestViewController.o)
".objc_class_name_NSNotificationCenter", referenced from:
literal-pointer#_OBJC#_cls_refs#NSNotificationCenter in Test3-Release.a(Test.o)
So it looks like it's not finding Foundation and UIKit frameworks for the library?
Here's what I've done so far:
I have 2 projects: 1 is a library project with a library build target. The other is a Test Project that tries to use the library built in the first library.
1) Create a project with a static library target and added all of the implementation files
2) Added libraries like UIKit, Foundation, etc to the "Link Binary with Libraries folder and Set all the linked libraries to have a weak type in my library target.
3) Built the library, added it to my test project, along with my header files.
4) In my test project, I set other linker flags to -ObjC -all_load for all build configurations
When I compile it gives me a bunch of errors as if I didn't include any frameworks.
Anyone have any ideas on what I should do?
Hint (Maybe?)
I also noticed that adding any frameworks to the "Link Binary with Libraries" folder in my library target doesn't seem to do anything. I added CoreLocation to that folder, but when I try to compile in my Test Project it won't compile until I add CoreLocation to my Test Project Frameworks folder.
your dependent project (that uses static library) hassn't linked Framewrok libraries.
Just add to dependent project frameworks (uikIt,Foundation, etc) all will work fine.