Compiling for power pc?

Discussion in 'Mac Programming' started by Jaqen, Aug 14, 2009.

  1. Jaqen macrumors member

    Joined:
    Nov 18, 2006
    #1
    Hey, I'm making a cross platform game and I have it running on windows and my intel mac just fine. Tried to give it to my brother and it says invalid architecture when he tries to run it. I'm assuming it's cause he has a powerbook g4 which I believe is powerpc. What do I need to do to compile it so it'll run on his? Will I be able to do it on my macbook (just a matter of changing some settings in xcode?) or would I have to actually go and compile it on his machine?

    Oh and one other thing about compiling on OSX/xcode... when I run the program from xcode the images and everything loads just fine. If I try to run it by opening the .app file, none of the images load. What do I need to do here? I tried copying the directories (data/images) to the directory the .app file is in but still no go.


    Thanks all.
     
  2. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    You need to set Xcode to compile for the PowerPC architecture as well as the Intel architecture in project settings.

    You have most likely hard coded the paths into your application. When Mac OS X bundles the application up into a .app it puts resources into a different folder. I believe there is a variable relating to the root of the app bundle but I forget exactly what it is.
     
  3. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #3
    You would use NSBundle to load resources from your bundle.
     
  4. Sijmen macrumors 6502a

    Joined:
    Sep 7, 2005
    #4
    Let me clarify this a bit more: you should put your resources like images and sound in the Resources folder in Xcode. Then, when compiling, it'll place it in the correct location for the app. You can use NSBundle to locate these resources.
     
  5. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #5
    If you're using Xcode 3.x, the most likely cause of your problem is you used the Debug build configuration, which doesn't build universal binaries. Change the active build configuration to Release, and Xcode should build a universal binary.
     
  6. Jaqen thread starter macrumors member

    Joined:
    Nov 18, 2006
    #6
    It is set to build in release mode. Under project settings it says...

    Architectures: i386
    Valid Architectures: ppc64, ppc7400, ppc970, i386, x86_64ppc

    What exactly am I changing in project settings? Cross develop using Target SDK was set to 10.5... should I change this to 10.4 (universal)?


    And the paths to the files aren't hardcoded. I'm using paths like "images/foo.png". When you guys say to use NSBundle, from what I can tell from googling it, it's a class? Would I just be creating an instance of that class and then listing all my files or something?
     
  7. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #7
    Modify the Architectures build setting. I don't know what version of Xcode you're using, but in Xcode 3.1, you should set Architectures to Standard (32-bit Universal).

    You may also need to modify the Deployment Target build setting for your game to run on your brother's Mac. The deployment target is the earliest version of Mac OS X that can run your program. It is initially set to the version of Mac OS X you're running, which is most likely 10.5. You'll need to set the deployment target to the OS version your brother's running.

    This blog post should help you with your bundle question.
     
  8. Jaqen thread starter macrumors member

    Joined:
    Nov 18, 2006
    #8
    How do I use NSBundle? What do I need to include? I tried #import <Cocoa/Cocoa.h> but then that suddenly made my project have 2000 errors for some reason.

    Still couldn't get the compile thing working for some reason so just decided to compile it on his mac.
     
  9. Sijmen macrumors 6502a

    Joined:
    Sep 7, 2005
    #9
    Cocoa is written in Objective-C and thus you can only use it from Objective-C code.

    Depending on what language you are using, I suggest this:

    • C: Create a header file, like mac_support.h, and in it create functions like GetPathOfResource(blabla). Create an Objective-C implementation file, like mac_support.m. There you can include Cocoa.h and use NSBundle methods when implementing the function.
    • C++: Declare a C++ class in a header, like MacSupport.h. Create an Objective-C++ file like MacSupport.mm, where you can mix C++ and Objective-C code when implementing the methods.

    You still need to do some string conversions etc, but I trust that with the help of the NSString class reference you can sort that out.
     
  10. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #10
    Did you add the Cocoa framework to your project? If you didn't, you're going to get compiler errors if you try to call any Cocoa functions.

    Since your game is cross-platform, you probably used a cross-platform game library like SDL or Allegro. What library did you use? If you used SDL, modify the method setupWorkingDirectory in the file SDLMain.m. The blog post I linked to earlier contains the code to put in the method. If you used another library, someone else will have to help you.
     

Share This Page