compile c code on mac for use on iphone? - iphone

How would I go about setting everything up to cross compile from my OSX 10.6 Macbook pro with xcode to my jailbroken 4th generation iPod touch. I'm mainly aiming to be able to port open source libraries to iphone. I can't seem to find any good/recent articles on cross compiling for iOS 4.

If you think about it, all projects built in XCode are cross-compiled for the iPhone. All you have to do is open an ios project, include your sources and build it.
More specifically, when you have a project in XCode, in the Build Settings tab there is an option for you to specify the architecture to compile - this is automatically set to something like 'armv7' for ios projects.

Related

Run A multiplatform xcode project

I have a project that has two targets one for iOS and other OSX. When I run the project it builds successfully. But Its nit running.I want to run this ample project in any of the platform. How can I do this.
This won't work, because iOS and OS X are based on different frameworks.iOS needs UIKit. But if you compile a project for Mac that contains UIKit, you will get an error. You cant just set Xcode to compile for Mac if you use the wrong 'base classes'.
Just create 2 Xcode projects that contain all the classes you want to use, one for OS X, one for iOS.

iOS simulator only list the latest iOS version. How can I set earlier versions

According to the documentation should be able to choose which iOS version the simulator should run, however only the latest 4.3.2 is listed under "Hardware/Version".
The helps says:
"To set the iOS release used in the simulation environment, choose Hardware > Version, and choose the version you want to test on."
I don't want to support 3.x (although it would be nice) but at least I want to simulate my app on 4.2, 4.1 and 4.0.
What's going on? Why aren't they listed?
UPDATE:
I'm on Lion so I cannot install an earlier version of Xcode. Before my Upgrade I could test different versions easily.
the problem is that you have no other Simulator SDK installed which can be used. As #dorada has mentioned you have to install an older Xcode which in fact doesn't work because you're using Lion. I haven't tried it with Lion but principally it should work like before with Snow Leopard.
I'm referencing to my other answer how to get an older Xcode (don't know if it's still working)
After you have an older Xcode version, mount the image an navigate with terminal to that volume. There should be a hidden folder Packages. open that folder with open . and locate the two .pkg files you need (e.g. iPhoneSDK4_0.pkg and iPhoneSimulatorSDK4_0.pkg) and install both.
They will appear in your root directory and you have to move them to your Developer dir (don't simply overwrite, it will delete all other SDKs. go to the last different folder it should be iPhoneSimulator4.0.sdk\ and copy that one)
DONE (and at that point I have verified it: it works on my Lion. I used the dvd image which I have started backup'ing since 3.2.1)
Although iPortable has the correct answer I decided to post a step-by-step guide which is easer to follow:
Download Xcode 3.1
Mount the dmg file
In Finder menu select "Go\Go to folder" and enter "/Volumes/Xcode and iOS SDK/Packages"
Install the simulators you need (Double click)
Copy the simulation folders from /Platforms/iPhoneSimulator.platform/Developer/SDKs/ to /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/
If your have some SDK missing Install the missing SDK from "/Volumes/Xcode and iOS SDK/Packages" and copy subfolders from /Platforms/iPhoneOS.platform/DeviceSupport/ to /Developer/Platforms/iPhoneOS.platform/DeviceSupport/ (for me they were all there from 3.1 to 4.3)
you may download the older ios sdk / xcode from . https://developer.apple.com/downloads/index.action
(i found this answer in another stack overflow topic actually, but now i can not seem to find that question!)
Open Xcode and in the menu at the top left, where you select what device to run on, click "More Simulators..."
The download section of Xcode preferences will open,
Click the "Components" tab.
You will see a list of simulators that can be installed, click install on version you need.
The simulator will need to restart to install.
To run the newly installed version of the simulator just select it from the run menu in Xcode.
You actually have to install previous simulator versions, they aren't there on a new install.
Maybe you can search and download them somewhere? - we keep them on a shared drive at the office.
After installing the Xcode 4.2 for Snow Leopard, I noticed there was a choice for iPad 3.2 Simulator, but using it just brings up some alerts that say "iOS Simulator could not find the SDK. The SDK may need to be reinstalled." and another alert that says "Simulated application quit. Click Relaunch to try again." with Quit, Switch SDK, and Relaunch buttons.
I can successfully use iPhone 4.0 Simulator, iPhone 4.1 Simulator, iPad 4.2 Simulator, etc up to iPad/iPhone 5.0 Simulator, but really would like to have iPad 3.2 Simulator and iPhone 3.1.3 Simulator and earlier down to 3.0 if possible.
Our apps generally run all the way back to 3.0 and we occasionally receive bug reports from earlier iOS users, and would love to be able to debug these issues more effectively.
I tried the technique summarized by Tibidabo and although I am able to copy the simulator folders as mentioned, and though they show up as choices in Xcode, I cannot get them to actually run as simulators and I get the same problem alerts mentioned above.
What are other developers doing to support debugging of older iOS versions?
Go to Project Settings -> Summary an change Deployment Target.

Xcode 3.2.3 and up - static libs with targets for multiple platforms

I have a static lib project with targets for iPhone and for os x.
With Xcode 3.2.2 and earlier versions all worked just fine, but in 3.2.3 apple seems to have introduced changes in how to handle target settings.
In 3.2.2 I just could choose "base-sdk" from drop-down menu and set up a target for each, iPhone simulator, iPhone device and Mac and xcode would always automatically build for the correct platform and architecture for that target.
Now, with xcode 3.2.3 and later you can't choose this option any more.
Switching between targets for simulator or device does not have influence on the platform, you build for, anymore. You always have to choose the platform separately and then all targets are build for that platform.
This issue is already described for simulator vs device here:
Targeting multiple platforms in iPhone SDK 4
For iPhone only projects I could live with it and just only have one target and choose the platform separately from the target.
The real issue with that change is with having an iPhone and a mac target in the project:
if the mac target is chosen, you do not have the option anymore, to switch between device and simulator, but they still affect the mac target.
If the platform has been set to device prior to switching active target from iPhone to mac, than xcode does not find the CoreServices for the mac target, because it is searching in iPhone device frameworks, where this isn't existing. Xcode even builds for arm in this case, also the target settings clearly tell it to build for i386.
If switching back to iPhone target an setting the platform to simulator and then switching back again to mac target, CoreServices framework is found, but the simulator one is used, not the os x one, which leads into the issue of dozens of "error: expected declaration specifiers or '...' before 'CFXMLTreeRef'" errors in the iphone simulator core services framework, where this is not defined, although I do of course want to use the mac version of the framework for mac target.
As I already mentioned, this was all working fine before Xcode version 3.2.3. Projects only for iPhone or only for mac are still building fine.
Any ideas, how I can get projects with static libs targets for iPhone and for mac, to build with Xcode 3.2.3 and later versions?
this guy has the solution...
http://blog.vucica.net/2010/09/single-xcode-project-for-ios-and-mac-os-x.html

Compiling for iOS 3.1.3, using xcode 3.2.3 (and iOS 4 that came with it)

I've downloaded the final version (and never installed any beta versions before) of xcode 3.2.3 with sdk 4, and now I can't seem to find a way to compile my app for a 3.1.3 iOS.
Does anybody know how can I do that ?
As it is, you can't. They probably did this on purpose to discourage new apps compiled for 3.1.3 which foils multitasking.
Instead you can compile for iOS 4 but make your deployment target 3.1.3. This doesn't really require any more real work, as long as you don't use any non-3.1.3 methods/classes etc. and the application can install and run on a 3.1.3 device. You can also then make your application multitasking aware so that it works nicely on a device that does run iOS 4 and is capable of multitasking.
Just a note: the Base SDK may be set at the project level, but you will need to go to the build settings for the target itself to set the deployment target (that setting is not available at the project level).
To expand on Jason Coco's answer:
If you go to the Project Info screen and click Build, you can choose what Base SDK to use (4.0) and then scroll down to iPhone OS Deployment Target version and set it to 3.1.3 or whatever.
However, you also have to go to the Targets section under Groups & Files (red bullseye) select your target and get the Info build page, and set your iPhone OS Deployment Target there too.
Once that's done, you should be able to test it with a device that's still running 3.0 or whatever you selected.
if you want to be compatible with iPhone OS 3.x you still compile for SDK 4.0, but open target settings and choose that application can run on 3.x (iPhone OS Deployment Target). If you did not use any iOS 4.0 specific APIs then your app will run smoothly on 3.x and 4.x, here is a screenshot of setting to change:
Screenshot

Why is the iPhone Simulator 3.0 not showing up in Xcode?

I have installed the new 3.0 SDK, but when I start up Xcode, I don't see an option to build for "Device - iPhone OS 3.0" or "Simulator - iPhone OS 3.0"
The Xcode About box says I am running: 3.1.2
Is there something else I have to do?
I think you need to upgrade to Xcode 3.1.3. I have the latest version and that's what my About box reads.
If you are sure you downloaded the latest version, perhaps you installed in to a different location?
If you are using an existing project you may have to tell your project to build to the 3.0 targets. I didn't have to do this for any of my projects but ...
Under the Deployment section of your project properties you should see:
iPhone OS Deployment Target - (change this to use iPhone OS 3.0)
You can also check that the Architectures section has the Base SDK set to 3.0.
This happens quite often when downloading Apple's sample code projects which are targeted for iOS 3.x but you've got iOS 4.x.
To show Simulator option go to Project Info window -> General tab -> Base SDK for All Configurations - choose Latest iOS.
If it doesn't appear straight away, close and reopen Xcode.
This is what worked for me:
I clicked on the box (where I expected iPhone Simulator to be shown), right clicked manage scheme. After that deleted all schemes, and in similar way, created a new scheme. It automatically produced all simulators including the ones for devices.