Hi,
I have an iPhone project I've been working on, I wanted to strip out the socket and bonjour libraries and compile them for OS X, should have been simple. I've now tried to add a simple command-line executable target to the project 3 times (luckily I backed up the whole thing beforehand) and I've been totally unable to achieve it. Either I just cannot get one or other of the executables to build, or I get them to build but one or other of them won't run and eventually I always get to a point I've screwed the project up so badly .. I have to revert it. I normally end up breaking the iPhone app even though I'm not really touching that configuration.
What I've tried is always along the lines of Project .. New Target .. Cocoa Shell Tool. I've then gone to that target, set the base SDK to 10.6 (or whatever .. mostly 10.6). Then I've added in just a very simple main.c added it to that project, built. Then I add a new executable, the one I just built, into the executables list. Once I get a simple hello world program working, I click the two source files which are common and add them to the shell tool project and then start messing about trying to get the right Frameworks to build things. Eventually, well often quite quickly, my iPhone project stops working.
Two things which I've found particularly annoying, is there a way around either of these please
1) Switching the 'active target' doesn't switch the SDK or executable, even though that target only has say OS X 1.6 and makes a different executable. You have to switch all 3 of them independently.
2) If I have to add a framework to the 'shell tool' project, it adds it in 'red' because even though I've chosen "Relative To Current SDK" and even though my Current SDK at the time I add it is correct at OS X, it tries to resolve the thing relative to the iPhone SDK (Base SDK for all Configurations I believe) and can't do it.
Anyway .. to my current isssue, having got a command line tool to build very simply I went back to my iPhone project, built it (no source changed AT ALL) and now it crashes failing to load a dynamic library which doesn't exist and never would. I've enabled DYLD_PRINT_LOAD and here are the lines at the end of my output which differ from the 'working' project. As you can see for some reason it tries to load the SocketTest app again (which is strange as it's already loaded it from /Users/rols/Library/Application Support/iPhone Simulator/User/Applications/D772AFCB-9AAE-4E87-8BE3-5086BC73DE27/SocketTest.app/SocketTest) then it tries to find a UIKit in /System/Library/Frameworks .. etc, which has the feeling that it's lost the plot about where the base SDK root is, note that it's already loaded UIKit earlier from the right place. At this point I get a SIGTRAP and the simulated program aborts. I have the full output of dyld from the working and non-working versions but it's long so I've just posted the end, the bit where it differs, the working program never tries that second dyld load.
2009-12-10 14:17:06.799 SocketTest[18283:207] Service is Running:yes dyld: loaded: /Users/rols/Documents/Code/C/SocketTest.broken/build/Debug-iphonesimulator/SocketTest.app/SocketTest dyld: loaded: /Developer/Applications/Xcode.app/Contents/Resources/../PlugIns/GDBMIDebugging.xcplugin/Contents/Resources/PBGDBIntrospectionSupport.A.dylib dyld: loaded: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation dyld: Library not loaded: /System/Library/Frameworks/UIKit.framework/UIKit Referenced from: /Users/rols/Documents/Code/C/SocketTest.broken/build/Debug-iphonesimulator/SocketTest.app/SocketTest Reason: image not found
I've looked at the build command log and really cannot see any differences between the build of the working and non-working version, no extra libraries added in, no extra paths I can see which are baked in somewhere. I've tried messing about with otool but haven't found anything clever there, that just seems to have the paths for needed libraries without any kind of SDK prefix, I assume that comes from somewhere else. I see nothing special in the executable flags between the working and non-working version .. I really actually just don't see the difference at all.
Should I even be really doing this? Is trying to add an OSX app to the same project as an iPhone one just asking for pain and misery because there is basic configuration information baked in which says 'this is an iPhone app' or 'this is a Cocoa app'? I could just make a brand new project, keep the few common files in a single directory and reference them without copying, but I always thought it should/would/could be easy to add nicely totally independent targets and executables to the same project and have one nice codebase you just compile different targets with.
And finally are there any of the tools I could have used (like otool) to answer some of my own questions about why these things are happening? I'm not an otool expert, I did try reading the docs and trying things, I didn't find anything useful.
Thanks and apologies for the long mail - tried to get a lot of facts in there.
Roland |