Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Considerations for including library as binary vs source

Tags:

c

iphone

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?

like image 358
LeeMobile Avatar asked Jun 23 '09 19:06

LeeMobile


3 Answers

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.

like image 169
amrox Avatar answered Oct 19 '22 18:10

amrox


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

like image 22
hacintosh Avatar answered Oct 19 '22 18:10

hacintosh


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™

like image 26
Nick Van Brunt Avatar answered Oct 19 '22 17:10

Nick Van Brunt