PDA

View Full Version : Code compiled on a G4, works on Intel?




gaswerks
Dec 17, 2006, 09:16 PM
I have an older chunk of C code (gcc 4.0) built on a PowerPC platform that runs on my PowerBook G4 w/ OSX 10.3.9 and my iMac G5 w/ OSX 10.4.8. Command line executable reads an input text file, runs a few calcs, then dumps the output to a new text file. I cut-pasted the executable off the G4 and onto the G5 and it ran without any issue. Subsequently and accidentally wiped make files etc from G4, so rebuilding executable could take me some serious time.

I am now looking at a new Intel machine. Can I do the same executable cut-paste onto and Intel Mac (assuming OSX 10.4.8) and have it run? Without recompiling would the code execute similarily on Intel?

<gaswerks>



iMeowbot
Dec 17, 2006, 09:23 PM
As long as the program doesn't do anything too deep (not a device driver, plugin, etc.), Rosetta will probably run it fine.

If there is an Apple dealer nearby, perhaps you could pop the program onto a CD, bring it in, and give it a try before you buy.

fivetoadsloth
Dec 17, 2006, 11:21 PM
As long as the program doesn't do anything too deep (not a device driver, plugin, etc.), Rosetta will probably run it fine.

If there is an Apple dealer nearby, perhaps you could pop the program onto a CD, bring it in, and give it a try before you buy.

yeah you should be fine and apple stores are really good about letting you try things on there machines. Good luck.

garethlewis2
Dec 18, 2006, 03:07 AM
If you are coding in XCode do the following.

1. Make sure your program works and does not crash leading to horrible crap errors etc.

2. Open Terminal.app

3. Goto the directory containing the project you have created with XCode.

4. In the directory with the project file, type the command xcodebuild.

5. XCode will build the program into an executable, that is also a universal binary, even though it is only one file.

6. Type the file <app name> to see what is in the executable.

7. file 'will' print out <appname> (for architecture ppc) Mach-O executable ppc
<appname> (for architecture i386) Mach-O executable i386

8. Congratulations you have built your first UB. Now get back to work.

FireArse
Dec 18, 2006, 03:11 AM
Hey garethlewis2, that was some great advice. I remember there were some optimisations for G5 ppc over G4 ppc, is there any of the same for Xeon over Core Duo chips?

Thanks,

F

Soulstorm
Dec 18, 2006, 03:30 AM
Hey garethlewis2, that was some great advice. I remember there were some optimisations for G5 ppc over G4 ppc, is there any of the same for Xeon over Core Duo chips?

Of course there is. But what program are you developing so that you need to optimize for a specific hardware?

Also, you can use Xcode and avoid messing with the terminal app to make a universal binary (http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeUserGuide/Contents/Resources/en.lproj/05_07_bs_building_product/chapter_34_section_6.html). I find it much easier this way.

garethlewis2
Dec 18, 2006, 03:48 AM
Or you could just do as I wrote and use xcodebuild, since you

A. Don't have to change the project from debug to release.

B. Worry about making sure you switched zero-link off.

C. It's the recommened way start deployment.

Soulstorm
Dec 18, 2006, 06:25 AM
Or you could just do as I wrote and use xcodebuild, since you

A. Don't have to change the project from debug to release.

B. Worry about making sure you switched zero-link off.

C. It's the recommened way start deployment.
A and B) You make it sound as its bad, but it is actually a lot easier to do that than opening terminal, typing the commands etc. My way, it's just a 2-button thingie to do. Also, if you have zerolink active, and you have built your project in this basis, the terminal will get you errors. At least that happened last time I checked. Avoid allowing zerolink, unless you plan on deactivating it soon.

C)Why is that? Recommended by whom if I may ask? (I really don't know, I'm just asking)

garethlewis2
Dec 18, 2006, 09:22 AM
It is recommened by all dev teams as it allows the build to be run at night. Since CVS or subversion can be controlled by a script, most build systems will do the following.

cvs checkout all the source code and resources needed for a build.

The project file for the entire project need to be somehow built. You should not be using the project file for a single developer out of a team. What happens if their project file for release only builds for PPC, etc.

xcodebuild can then build the system.

Next you can deploy the built app to wherever it is required.

This of course can be done graphically, but it is tedious and having an automated system almost always cuts out human error.

If you are just working on your own, then building in XCode is a simple solution. If you are part of a team, you will want to use a build tool. Whether it is built from bash, perl, etc is irrelevant. It needs to be done for a team, so the developers don't start tearing their hair out wondering why code that compiles and executes correctly on their machines won't work on a near identical machine at a client site.

iMeowbot
Dec 18, 2006, 10:13 AM
It ought to be pointed out here for future readers that xcodebuild does not help with the problem in the original post, missing makefiles.