How would I include open source library in my iPhone application? - iphone

I have found an existing open source library that I would like to include in my iPhone project (the unrar source code found here: http://www.rarlab.com/rar_add.htm ).
I have compiled this source as a linked library on my Mac with "make lib" which creates the libunrar.so file just fine.
These are the makefile settings for that target:
lib: WHAT=RARDLL
lib: $(OBJECTS) $(LIB_OBJ)
#rm -f libunrar.so
$(LINK) -shared -o libunrar.so $(LDFLAGS) $(OBJECTS) $(LIB_OBJ)
Obviously I can't use this on iPhone but I imagine I should be able to compile with different options to make a static library that I can use.
Do I:
Compile it on the Mac with different make options then drag the resulting library (some kind of .a ?) into my xcode project?
or
Drag all of the source code into my xcode project and create special targets of some kind to create it?
or
Something else entirely different?
I've been working on solving my unrar problem for a couple of weeks now and I believe using this library will give me the best results but I just don't know the final steps to make use of it.
Thanks for all advice.

I think that you'll probably want to do the easiest thing first, create an empty iPhone project and bring all of the code into it, just to see if it will compile.
If so, you may want to use the empty project to aid in the development of an Objective-C wrapper, once that is complete you can bring the code into your existing project for integration and testing.
If it looks like this is code that you would like to use with other projects, or you are feeling giving and would like to provide an iPhone port of the code, go ahead and pull this together into a library.
Here is a site that documents the process.

Related

I seek library project for iOs built with makefile

I am looking for a simple library ( and/or app - eventually want both ) example ( like a math library or whatever) for iOS which has a makefile for it that I can use as a template to make other makefiles from and learn. Static of course, (and dynamic if iOS supports it so I can have 2+ apps that share common code)
There is lots of incomplete and cryptic info out there but so far I havn't found any nice concise "with these source files" you create a makefile this way to build an iOS "fat" library I can import into other projects.
This would be on a Mac with the ios4 sdk installed.
It is always great to start with something that basically works.
I have created complex makefiles before for unix and windows and for other devices.
thanks.
The first link pictorially represents the process step by step that you've asked then the second link contains a package that allows a programmer to compile a make file based project
click me
click me
If you want to build a static library using a make file and link against it every time you build your Xcode project, you can add a "run script" build phase in your project before all the others, which runs this make file, and then add the built library to your linking phase. If you want a make file that builds the entire iOS project, I don't think it's posible (you can use the command line to compile the project without Xcode opened though).

iPhone static lib

i want to share some code with other iOS projects. So I create static library.
When I use this library in other projects and use header file from that lib I get an error like No such file and Directory. Can any one tell me fixes of it.
Here I get reference for making static lib
http://www.amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html
I downloaded that sample. It is also not working in my case. So please help me to fix that error.
Thanks in advance
My guess would be because the blog, whilst detailed, is probably a bit old now. Like anything there's a thousand ways to skin a cat.
You can now create frameworks for the iPhone sdk and include both simulator and device versions of the classes. Frameworks have the advantage that they can simply be dragged and dropped on Xcode to include them in a project. In addition I like to store my frameworks in version numbered directories so if I make changes, dependent projects can still use the old ones until I'm ready to update them.
I don't do it, but for the above reasons I'm not sure I'd drag and drop a libs project on a client project. To me the idea of a static framework is that it's independent on it's clients. Dropping it into client projects makes a connection between the two projects that is too tight.
Anyway do some searches on lipo and static frameworks. I also have so scripts in my project at https://github.com/drekka/dUsefulStuff that you mint find useful.

How to build command line tool in iphone project

I just started programming in Xcode and I'm trying to write an iphone application. I started out with a simple template for Iphone development and took it from there. Now I would like to build a command line tool (for converting data) which reuses some of the classes in my iphone project. I managed to add a new target 'convert', link the appropriate source code to the target, make the target dependent on the main target. Everything builds, so far so good, but it does not generate the right executable, it will build only build/Debug-iphonesimulator/convert which is not runnable from the command line (I'm guessing because it is not linked with the right libraries).
~/Documents/XCode/SQLiteTutorial> ./build/Debug-iphonesimulator/convert
dyld: Symbol not found: _OBJC_CLASS_$_NSCharacterSet
Referenced from: /Users/marc/Documents/XCode/SQLiteTutorial/./build/Debug-iphonesimulator/convert
Expected in: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
in /Users/marc/Documents/XCode/SQLiteTutorial/./build/Debug-iphonesimulator/convert
Trace/BPT trap
Is this possible with xcode at all? I'm not sure what kind of extra information you would need to answer this question, so let me know what to provide, if anything.
Kind regards,
Marc van Kempen.
What if you simply created a different project entirely and then dragged in the relevant classes you wanted to reuse, but instead of copying them, merely used references to them? Just don't select 'copy items into destination's folder' option when you drag the class files into your groups & files pane. That way your CL project always uses the latest version from the main iPhone one.
Having it all in one project would no doubt be cleaner though.
iPhone SDK does not officially support building command-line tools. iPhone does not run command-line tools; at least, not without jailbreaking.

Considerations for including library as binary vs source

I'm trying to write an SSH client for the iPhone, and I'd like to use the libssh2 open source library to do so. It's written in C.
How should I include this C library for my iPhone app? Should I compile it into some binary that I include into the my app, or do I add all the source to my project and try to compile it along with the rest of my app?
I'm interpretting this question as:
"Should I compile the C library code once, and include the binary library in my project? Or should I include all the source and compile it every time I build my app?"
It depends. One of the projects I work one depends on several external libraries. Basically, we have a simple rule:
Do you think you will need to change code in the C library often?
If you will be changing the code, or updating versions often, include the source and build it with the rest of your project.
If you're not going to change the code often or at all, it might make sense to just include the pre-built binary in your project.
Depending on the size of the library, you may want to set it up as a distinct target in your project, or for even more flexibility, as a sub-project of your main project.
If I was in your place, I would build libssh2 ahead of time and just include the binary library in my iPhone project. I would still keep the libssh2 source around, of course, in case it does need to be re-built down the road.
I have an iPhone app that is 90% c. I have had no problem adding 3rd party sources to my project and compiling. I am using Lua, zLib, and libpng with no modifications. I've also included standard libraries like unistd and libgen and they just work™
The Three20 iPhone library has a great howto on adding their library to your xcode project. Give that a shot.
I think you will find in the long run you will be better off building it into a standalone library and linking it with your application. This makes it easier to integrate into future apps. Another benefit is that it encourages code separation. If you feel pretty confident with the library, you can link your debug exe to the release build of the library and get some extra performance.
I can't really think of any downsides to creating a library, after the initial cost of setting it up, and having an extra project to modify if you have some changes that need to be made to all your projects. Even if you don't know how to make a library for the iPhone, this is a good excuse to learn.
Just adding the source to you project should work fine as well.

Best way to share iphone and mac code between projects

I realise that the view/controller stuff will be different between Mac and IPhone apps but the model code may well be similar/the same. So whats the best way to organise a project(s) so that the model code is/can be shared?
Copy/paste - just duplicate it and manually keep it in sync
Have 2 xcode projects point at the same workarea - one for Mac and one for IPhone and share the code.
Common library - presumably you can't do this (or can you)
Thanks for any tips.
There are a few ways to do this. The first thing you can do is is create a project that builds as a framework on Mac OS X. Since you cannot use frameworks on iPhone, you can make static library target that contains the same code files. That basically works, but the header paths will be different. If you want the header paths to be the the same (i.e. <Myframework/MyFramework.h>) you will need to modify the the install path of the static library headers so that they are copied into "$SDK_ROOT/usr/local/include/MyFramework", and make sure /usr/local/include is an included header search path. You will then need to install the library and headers into each SDK_ROOT.
I started out doing the above, but I found it to be a royal pain. So I ended up doing something that is a variant of #2. Basically, I get the header paths to be equivalent by making a directory named "Externals" in my iPhone project root, then a directory named with the appropriate name ("MyFramework") in the externals folder. That is the folder I copy I drag the framework files into.Findally I add the Externals folder as a system header path (which is admittedly sort of a gross hack). You need to manually add new files to the iPhone project, but I have found that to be less of a pain the installing static libs into my build root.
I'm not sure if the suggestion from the previous answer would work. If you look at my previous question, you'll see that I've failed to load a custom framework on the iPhone even though the framework works fine on Mac.
I would go with method 2.
You could develop your application in JavaScript, CSS, and HTML. You would use the WebView and UIWebView objects on the Mac and the iPhone respectively. You can do pretty much anything you want in the WebView objects, even make calls down to Objective-C.
The QuickConnectiPhone installer, found here https://sourceforge.net/projects/quickconnect/, installs QuickConnectMac and QuickConnectiPhone templates into Xcode.
This way you can quickly create an application in one environment and then migrate the view to the other. In fact the QuickConnect framework is highly modular.
If you don't want to develop in JavaScript the same modular framework is found on the Objective-C side of the templates installed.
It should make it much easier for you to do what you are attempting.