{"id":681,"date":"2009-10-13T23:48:01","date_gmt":"2009-10-13T22:48:01","guid":{"rendered":"http:\/\/t-machine.org\/?p=681"},"modified":"2011-02-03T15:10:59","modified_gmt":"2011-02-03T14:10:59","slug":"how-to-make-an-iphone-static-library-part-1","status":"publish","type":"post","link":"http:\/\/new.t-machine.org\/index.php\/2009\/10\/13\/how-to-make-an-iphone-static-library-part-1\/","title":{"rendered":"How to make an iPhone static library &#8211; part 1"},"content":{"rendered":"<p>I&#8217;ve now deployed iPhone static libraries in two (live) applications, and numerous updates.<\/p>\n<p>This is a process that is seemingly (*) 90% undocumented by Apple, despite being (IMHO) absolutely essential for any professional iPhone developer.<\/p>\n<blockquote><p>UPDATE: Apple changed everything (again) without telling developers (again) and broke everything (again).<\/p>\n<p>Current versions of Xcode (the minimum that Apple allows you to use) will *not* work with the architecture-link part of this blog post.<\/p>\n<p>Instead, see this StackOverflow question I asked (and answered) with an updated technique: <a href=\"http:\/\/stackoverflow.com\/questions\/3520977\/build-fat-static-library-device-simulator-using-xcode-and-sdk-4\n\">http:\/\/stackoverflow.com\/questions\/3520977\/build-fat-static-library-device-simulator-using-xcode-and-sdk-4<\/a>\n<\/p><\/blockquote>\n<p>[(*) &#8211; if there&#8217;s docs, then I&#8217;ve not found it in over 6 months of googling, searching Xcode doc libraries, and asking everyone I know. I will feel stupid if it&#8217;s there and I haven&#8217;t found it, but I have honestly tried very hard to find it!]<\/p>\n<p>I have sought help in numerous expert forums and mailing lists &#8211; and generally discovered that no-one else is quite sure how to do it either, although I&#8217;ve seen some funky ideas and methods that others have come up with.<\/p>\n<p>Through trial and error I&#8217;m pretty sure I know how to do it now &#8211; but I still have no idea what the &#8220;correct&#8221; approach is &#8211; so I&#8217;m writing up my best knowledge here, and I&#8217;m going to spread it to as many people as possible to get feedback from the 30,000+ other iPhone developers around the world.<br \/>\n<!--more--><br \/>\nFirst, some background&#8230;<\/p>\n<h4>The basics &#8211; Apple documentation<\/h4>\n<p>Apple&#8217;s documentation is absolutely terrible. It is shamefully, inexcusably, bad. It tells you:<\/p>\n<blockquote><p>\nDon&#8217;t use static libraries; static libraries are for idiots; you SHOULD use dynamic libraries for everything. This makes life easier for you (as a developer) and a lot cleaner for your users.\n<\/p><\/blockquote>\n<p>This is all ENTIRELY TRUE and extremely worthy.<\/p>\n<p>Sadly &#8230; Apple also states (if you follow their instructions for dynamic libraries on iPhone)<\/p>\n<blockquote><p>\nWe forceably prevent you from using dynamic libraries on iPhone; dynamic libraries are banned; you MUST use static libraries for everything\n<\/p><\/blockquote>\n<p>Apparently, someone at Apple &#8220;forgot&#8221; that they removed their docs on making static libraries some time ago, replacing them with notes to &#8220;use dynamic libraries and frameworks instead&#8221;.<\/p>\n<h4>The basics &#8211; Frameworks<\/h4>\n<p>Frameworks are awesome &#8211; well done, Apple! &#8211; but apparently they require dynamic libraries. I have never yet found anyone who managed to make an Apple Framework for iPhone; I don&#8217;t think it&#8217;s possible (although I keep trying&#8230;).<\/p>\n<h4>The basics &#8211; Universal Binaries<\/h4>\n<p>Universal Binaries are awesome &#8211; well done, Apple! &#8211; but Apple decided they were &#8220;too good for you, suckas!&#8221;, and removed them in iPhone OS 3.x.<\/p>\n<p>At least, I had techniques that successfully built and deployed UBs on iPhone in 2.2.1, but completely stopped working in iPhone OS 3.0. As far as I could tell, none of this &#8211; none of it! &#8211; is documented (of course!). I have given up on UB&#8217;s. But, if someone can show me an officially accepted way of doing UB on iPhone OS 3.x, I will be very happy.<\/p>\n<p>(NB: it *must* be officially accepted: I suspect that Apple deliberately broke \/ removed UB support for 3.x)<\/p>\n<h4>The basics &#8211; Source-code builds<\/h4>\n<p>Xcode is:<\/p>\n<p>The Worst IDE in The World &#8482;<\/p>\n<p>HOWEVER &#8230; it does have very good support for embedding references to one project (LIB) inside another project (APP), so that whenever you re-build APP, it automagically re-compiles LIB if &#8211; and only if! &#8211; it is necessary.<\/p>\n<p>However, that is only of relevance if:<\/p>\n<ol>\n<li>You have the complete source code AND build settings to ALL libraries you ever use (this is very unlikely)\n<li>Your distributed, caching, build system is complete crap, and you don&#8217;t actually use it\n<li>Your SCM is exceptional, and deploys entire &#8220;related&#8221; Xcodeproj directories for all revelant projects (this is very VERY unlikely)\n<li>You have a super-fast machine that compiles REALLY REALLY fast, and you don&#8217;t mind doing triggered re-builds of projects\n<li>You don&#8217;t mind spending several weeks tracking down non-existent bugs because of a dynamic mis-matching of library source versions\n<\/ol>\n<p>So, basically &#8230; it&#8217;s a useful feature for the hobbyist programmer, but most real studios can&#8217;t afford to rely upon it.<\/p>\n<h4>The basics &#8211; Device-only builds<\/h4>\n<p>The iPhone Simulator that apple provides to all iPhone developers is EXTREMELY good. It has four bugs \/ problems:<\/p>\n<ol>\n<li>It&#8217;s too fast (it makes NO attempt to run at the same speed as an actual iPhone)\n<li>It doesn&#8217;t simulate the different hardware revisions (you cannot select &#8220;3GS mode&#8221; as opposed to &#8220;3G mode&#8221;)\n<li>It doesn&#8217;t simulate multi-touch (and a few others, like &#8220;vibration&#8221;) and (bizarrely) doesn&#8217;t support odd things like some of the built-in animations\n<li>It uses a different CPU architecture &#8211; intel only, as opposed to the iPhone&#8217;s ARM chips\n<\/ol>\n<p>It takes a LONG TIME to download a freshly-compiled iPhone app to your iPhone &#8211; approximately 10 to 30 seconds, on average. This can easily extend the &#8220;change, compile, test&#8221; cycle on a (fast) Mac from about 20 seconds to about 40 seconds &#8211; i.e. literally a 2x decrease in productivity.<\/p>\n<p>Hence it is essential for serious iPhone devleopers to work on the Simulator as much as possible, and switch to the Device periodically (perhaps using the Simulator 30-50 times an hour, and the Device merely 3-5 times an hour).<\/p>\n<h4>Next post&#8230;<\/h4>\n<p>Followup, with details on how I solved all this:<\/p>\n<p><a href=\"http:\/\/t-machine.org\/index.php\/2009\/10\/14\/how-to-make-an-iphone-static-library-part-2\/\">How to make an iPhone static library &#8211; part 2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve now deployed iPhone static libraries in two (live) applications, and numerous updates. This is a process that is seemingly (*) 90% undocumented by Apple, despite being (IMHO) absolutely essential for any professional iPhone developer. UPDATE: Apple changed everything (again) without telling developers (again) and broke everything (again). Current versions of Xcode (the minimum that [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,20],"tags":[],"_links":{"self":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/681"}],"collection":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/comments?post=681"}],"version-history":[{"count":0,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/681\/revisions"}],"wp:attachment":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/media?parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/categories?post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/tags?post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}