views:

1323

answers:

6

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.

What is the best way to use 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?

How do I go about this?

Thanks,

iPhone and C newbie

A: 

+1 for a cool idea.

I know there are some existing ssh applications out there, try googling them to see if they have source available.

Or email the libssh2 maintainers

samoz
+1  A: 

The Three20 iPhone library has a great howto on adding their library to your xcode project. Give that a shot.

hacintosh
+2  A: 
Nick
Most of my app is C as well, except for where I can Objective-C APIs. I'm curious about your usage of Lua. Do you intend to distribute through iTunes? I'm asking because I'd love to embed an interpreter but I've been scared away by Apple's prohibitions against any interpreters not provided by Apple. Is Lua allowed in the app store?
Nosredna
You are free to use a scripting language however you can not allow people to load arbitrary code in it. To be safe I compile (hard code) the scripts into the app.
Nick
A: 

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.

Dolphin
+3  A: 

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.

amrox
A: 

How to build a iPhone libssh2.a file I am crashed

aelam
To ask a question, use the "Ask Question" button on the top right hand corner of the page. Also, try to be more specific about the error so someone can be specific about an answer
Fuzz