12

Each C/C++ library has some amount of headers that should be used with that library. And if you're use more than 1-2 libraries, custom header paths is kind of headache.

So I thought: is there a way to compile C libraries as frameworks. Static library + headers + versioning.

I found in XCode template for Cocoa framework but nothing about iPhone framework building. This simple step could allow developers to build and share between each other frameworks with some interesting code.

Also it would be great to use libpng, libjpeg and other libraries packaged as frameworks.

I won't use dynamic libraries in those frameworks. Only static version will be present.

Fattie
  • 27,874
  • 70
  • 431
  • 719
Evgen Bodunov
  • 5,438
  • 2
  • 29
  • 43
  • 2
    My 'foo_framework' uses quux_framework_20101231; your 'bar_framework' uses quux_framework_20110224. I want to use both my framework and your framework in a program of mine ... but quux_framework_20101231 and quux_framework_20110224 are incompatible. Now what? :) – pmg Mar 17 '11 at 15:13
  • Each framework contain versions folder. So foo.framework will use 'quux.framework/versions/1.0' and bar.framework will use 'quux.framework/versions/1.2' and if your lib depends on framework in general you will link just to 'quux.framework'. As I understand all that stuff. – Evgen Bodunov Mar 17 '11 at 15:25
  • I removed the `C++` tag, as you're looking for a way to convert C code and C++ is pretty irrelevant to the question. – Puppy Mar 24 '11 at 23:52

3 Answers3

5

I combined techniques I found here and here into my open source library here (NOTE - I have since removed the relevant scripts from this project. I have updated the link to point to the last revision that included these techniques.). Think that's basically the solution you're looking for.

Basically, it has a target that will build a fat static library (lipo builds for arm6, arm7 and i386). It has another target that takes that library and builds it into a framework.

There's no reason you can't use the same techniques for a C project. In fact I've started work on porting C the VTD XML parser to an Objective C framework using the same techniques.

Community
  • 1
  • 1
DougW
  • 28,776
  • 18
  • 79
  • 107
2

Frameworks are basically just bundles of dynamic/shared libraries. Since this is not allowed in the App Store, you have to build static libraries and link them with your App's executable at compile time.

However, to ease the pain a little, you can have a Xcode project for each library and compile each library into a static lib. Another way would be to put all required source files into the main Xcode project and configure it appropriately so it all builds at once (I did this with small libraries like Minizip, for instance).

Hope that helps.

BastiBen
  • 19,679
  • 11
  • 56
  • 86
  • Apple didn't allow only dynamic libraries. And i'm good to have only static version in my frameworks. Currently i use separate project with many targets, one target per library. And i use that project as external dependency in my application project. so it flexible enough, but i want more. :)) – Evgen Bodunov Mar 17 '11 at 16:54
1

the problem you are trying to make already exists - it's called DLL hell

Best way is to stick with plain old static libraries when making small apps and organizing source/headers structure

fazo
  • 1,807
  • 12
  • 15