Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dguisinger

macrumors 65816
Original poster
Jul 25, 2002
1,106
2,270
Alright, I'm looking for a fix to my problem.
I've been attempting to build a library to house common Obj-C code.
I've figured out apple doesn't allow custom frameworks, but they do seem to allow static libraries. So far so good, thats fine for me.

The static library appears to compile fine - however, the project thats referencing it blows up during link saying it can't find the classes in the .a library file.

I've never done static libraries in Xcode before, does anyone know how to solve this problem?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I haven't done this and I don't think anyone has posted how to do this but I do have an interest in figuring this out.

There's no project template for building a static lib for the phone. There are project templates for building static libs for Mac OS X. Compare those with the phone projects.

A few other odd comments:

There are some .a files in the SDK that could be used for comparison.

You can use the file and nm tools to inspect the .a files you generate.

This guy built libcurl as a static lib for the phone using a makefile

http://www.iphonedevsdk.com/forum/iphone-sdk-development/4580-curl-anyone-using-their-app.html
 

dguisinger

macrumors 65816
Original poster
Jul 25, 2002
1,106
2,270
Do you know, is there anything special one has to put in the header files to allow a ObjC class or interface to be exported in a library? (Having never written any type of framework in ObjC, maybe I'm missing something simple!)
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I think that for a static library everything is exported. It's basically just a bunch of .o files scotch-taped together.

Look at the settings in the Cocoa-based static library template project.
 

dguisinger

macrumors 65816
Original poster
Jul 25, 2002
1,106
2,270
Like i said, I got close to the point where the linker said objc_**** not found while linking.

I just don't have that much experience with Gcc or xcode (nor do I want to dive into it really, I believe in having solutions that ... just work). I doubt its that hard to fix, i just don't know which setting is correct.

I started from the OS X static framework template, and changed the CPU and OS settings to the iPhone 2.1 platform.

*shrug*

suggestions, anyone?

Right now my solution is to include source code into multiple projects, but thats dangerous because I could accidentally change a file or delete a file that is shared without thinking about it....
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I was challenged by your earlier comments so yesterday I built a static lib project. I've attached it here. It's had minimal testing. There are two projects in the archive. One builds a static lib with a single class that has a method named test. The other project includes the static lib and calls the test method. I tested it on both the Sim and device and it worked ok.

Let me know if it works for you.

I started with the CocoaStaticLib project and modified it to work with the iPhone SDK.
 

Attachments

  • PhoneyStaticLib.zip
    21.8 KB · Views: 218

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
Right now my solution is to include source code into multiple projects, but thats dangerous because I could accidentally change a file or delete a file that is shared without thinking about it....

I check-out shared files from a central SCM/CVS repository into any leaf project's directories, and make sure they're write protected.

.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.