Tutorial :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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »