Code compiled on a G4, works on Intel?

Discussion in 'Mac Programming' started by gaswerks, Dec 17, 2006.

  1. gaswerks macrumors 6502

    Dec 17, 2006
    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?

  2. iMeowbot macrumors G3


    Aug 30, 2003
    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.
  3. fivetoadsloth macrumors 65816


    Aug 15, 2006
    yeah you should be fine and apple stores are really good about letting you try things on there machines. Good luck.
  4. garethlewis2 macrumors 6502

    Dec 6, 2006
    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

    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.
  5. FireArse macrumors 6502a

    Oct 29, 2004
    Good few tips there!

    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?


  6. Soulstorm macrumors 68000


    Feb 1, 2005
    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. I find it much easier this way.
  7. garethlewis2 macrumors 6502

    Dec 6, 2006
    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.
  8. Soulstorm macrumors 68000


    Feb 1, 2005
    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)
  9. garethlewis2 macrumors 6502

    Dec 6, 2006
    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.
  10. iMeowbot macrumors G3


    Aug 30, 2003
    It ought to be pointed out here for future readers that xcodebuild does not help with the problem in the original post, missing makefiles.

Share This Page