Results 1 to 10 of 37

Thread: Linking Issues on MacOS X 10.6.5

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by Mario Donick View Post
    Also the FPC wiki says that you don't need to use the Framework, you CAN use the Unix way.
    This is not recommended. The end-user would need to install libSDL*.dylib and all SDL friends on their computer. The framework way is much better for deployment.

    I wouldn't bundle it with WineBottler, native applications are always faster than applications running through Wine.

    If you use "fpc -Mobjfpc -ve -k-lSDLmain -k-framework -kSDL -k-framework -kSDL_image -k-framework -kCocoa -Fl/usr/X11/lib fprl.pp" and the JEDI-SDL headers everything should work fine.

    Alternatively, you can add
    {$IFDEF DARWIN}
    {$PASCALMAINNAME SDL_main} // Needed for Snow Leopard
    {$linklib SDLmain}

    {$linkframework Cocoa}
    {$linkframework SDL}
    {$linkframework OpenGL}

    {$linkframework SDL_image}
    {$linkframework SDL_mixer} // If you are using SDL_mixer
    {$IFDEF USE_SDL_GFX} // If you are using SDL_gfx
    {$linkframework SDL_net} // If you are using SDL_net
    {$ENDIF}
    at the top of your main source file and compile your application with: fpc -Mobjfpc -ve -Fl/usr/X11/lib fprl.pp

    Btw: If you are still interested in Universal binaries, this is my Mac and Linux compile script which compiles an universal binary, copies all my assets and creates a nice .app file around the application. I've been using this in all my Mac FreePascal SDL game projects.
    #!/bin/sh

    FPC_BIN=`which fpc`
    BIN_FOLDER="../bin"
    SRC_MAIN="main.lpr"
    LIB_FOLDER="../lib"
    EXEC_NAME="execname"
    APP_NAME="My Application Name"


    cd ../source
    if [ -f /System/Library/Frameworks/Cocoa.framework/Cocoa ]
    then

    FPC_BIN=`which ppc386`

    # Compiling Intel binary
    ${FPC_BIN} @config.cfg -k-L/usr/X11R6/lib ${SRC_MAIN}
    mv ${BIN_FOLDER}/main ${BIN_FOLDER}/main-intel
    rm ${BIN_FOLDER}/link.res
    rm ${BIN_FOLDER}/*.o ${BIN_FOLDER}/*.ppu
    rm ${SRC_HEADER}/*.o ${SRC_HEADER}/*.ppu ${SRC_HEADER}/*.dcu ${SRC_HEADER}/*.a


    FPC_BIN=`which ppcppc`

    # Compiling PowerPC binary
    ${FPC_BIN} @config.cfg -k"-L${LIB_FOLDER}/frameworks -L/usr/X11R6/lib" ${SRC_MAIN} -XR/Developer/SDKs/MacOSX10.5.sdk/ -k-macosx_version_min -k10.5
    mv ${BIN_FOLDER}/main ${BIN_FOLDER}/main-ppc
    rm ${BIN_FOLDER}/*.o ${BIN_FOLDER}/*.ppu


    # Creating universal binary
    if [ -f ${BIN_FOLDER}/main-intel ] && [ -f ${BIN_FOLDER}/main-ppc ]
    then
    strip ${BIN_FOLDER}/main-intel
    strip ${BIN_FOLDER}/main-ppc

    lipo -create ${BIN_FOLDER}/main-intel ${BIN_FOLDER}/main-ppc -output ${BIN_FOLDER}/${EXEC_NAME}
    rm -rf ${BIN_FOLDER}/main-intel
    rm -rf ${BIN_FOLDER}/main-ppc
    fi

    if [ -d "${BIN_FOLDER}/${APP_NAME}.app" ]
    then
    echo " ... Removing old application"
    rm -rf "${BIN_FOLDER}/${APP_NAME}.app"
    fi

    echo " ... Creating Application Bundle"

    mkdir "${BIN_FOLDER}/${APP_NAME}.app"
    mkdir "${BIN_FOLDER}/${APP_NAME}.app/Contents"
    mkdir "${BIN_FOLDER}/${APP_NAME}.app/Contents/MacOS"
    mkdir "${BIN_FOLDER}/${APP_NAME}.app/Contents/Resources"
    mkdir "${BIN_FOLDER}/${APP_NAME}.app/Contents/Frameworks"

    cp -R ../resources/ "${BIN_FOLDER}/${APP_NAME}.app/Contents/Resources/"

    # Copy frameworks from System
    cp -R /Library/Frameworks/SDL.framework "${BIN_FOLDER}/${APP_NAME}.app/Contents/Frameworks/"
    cp -R /Library/Frameworks/SDL_mixer.framework "${BIN_FOLDER}/${APP_NAME}.app/Contents/Frameworks/"
    cp -R /Library/Frameworks/SDL_ttf.framework "${BIN_FOLDER}/${APP_NAME}.app/Contents/Frameworks/"

    mv "${BIN_FOLDER}/${EXEC_NAME}" "${BIN_FOLDER}/${APP_NAME}.app/Contents/MacOS/"

    echo "<?xml version='1.0' encoding='UTF-8'?>\
    <!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\
    <plist version=\"1.0\">\
    <dict>\
    <key>CFBundleDevelopmentRegion</key>\
    <string>English</string>\
    <key>CFBundleExecutable</key>\
    <string>${EXEC_NAME}</string>\
    <key>CFBundleIconFile</key>\
    <string>logo.icns</string>\
    <key>CFBundleIdentifier</key>\
    <string>com.freezedev</string>\
    <key>CFBundleInfoDictionaryVersion</key>\
    <string>6.0</string>\
    <key>CFBundleName</key>\
    <string>${APP_NAME}</string>\
    <key>CFBundlePackageType</key>\
    <string>APPL</string>\
    <key>CFBundleSignature</key>\
    <string>PSGR</string>\
    <key>CFBundleVersion</key>\
    <string>1.0</string>\
    <key>CSResourcesFileMapped</key>\
    <true/>\
    </dict>\
    </plist>" >> "${BIN_FOLDER}/${APP_NAME}.app/Contents/Info.plist"

    echo "APPLFDRS" >> "${BIN_FOLDER}/${APP_NAME}.app/Contents/PkgInfo"

    else
    if [ -f /usr/lib64 ]
    then
    ${FPC_BIN} @config.cfg ${SRC_MAIN}
    rm ${BIN_FOLDER}/*.o ${BIN_FOLDER}/*.ppu
    else
    ${FPC_BIN} @config.cfg ${SRC_MAIN}
    rm ${BIN_FOLDER}/*.o ${BIN_FOLDER}/*.ppu
    fi

    if [ -f "${BIN_FOLDER}/main" ]
    then
    mv "${BIN_FOLDER}/main" "${BIN_FOLDER}/${EXEC_NAME}"
    fi
    fi
    If you want to use this for your projects, you need to change the variables at the top (BIN_FOLDER, SRC_MAIN, LIB_FOLDER, EXEC_NAME and APP_NAME) to the value you want them to be. You need to delete the reference to config.cfg if you are not using a config file for your project and libSDLmain.a should be in LIB_FOLDER/frameworks for PowerPC compilation.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  2. #2
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    oooh, shiny. i must say; i do appreciate bash scripts a lot. now where can i use this seeing i dont have mac? hmm. tough one
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  3. #3
    @Stoney, thank you! This looks like a great solution, I'll try this now and report back soon.

    Edit:

    I added the IFDEFs at the beginning of my main file. Here the results:


    1. When I use the single compiler call you gave me above, with the JEDI SDL headers (not the ones included in FPC), the game compiles and links, but crashes as soon as it tries to call SDL_INIT.

    2. When I use your build script, it tells me:

    Code:
    Linking fprl
    ld: warning: in ./libSDLmain.a, file was built for unsupported file format which is not the architecture being linked (i386)
    Undefined symbols:
      "_main", referenced from:
          __start in crt1.o
         (maybe you meant: _SDL_main)
    So nothing has changed.

    The libSDLmain file was created by me some days ago using the "devel-lite" folder in the SDL for Mac download, and using the following compiler call (as stated in the FreePascal wiki):

    Code:
    gcc -c -o SDLMain.o SDLMain.m -I /Library/Frameworks/SDL.framework/Headers
    ar r libSDLMain.a SDLMain.o
    ranlib libSDLMain.a
    But somehow the resulting library seems not to be correct.
    Last edited by Mario Donick; 09-01-2011 at 09:30 AM.

  4. #4
    The problem seems to be that the libSDLmain.a you made is 64 bit, which is done by default if you have Snow Leopard installed. You need to explicitly compile the library for i386 and PowerPC if you plan to make Universal Binaries.
    You can have my libSDLmain.a (it has i386, x64_64 and ppc all in one file): Download here

    Edit: If you use my build script you might want to change CFBundleIdentifier and CFBundleSignature for your application.
    Last edited by Stoney; 09-01-2011 at 09:52 AM.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  5. #5

  6. #6
    Awesome I guess we really need a tutorial for new Mac OS X users.
    Btw: If you would want or need to compile libSDLmain.a for yourself for i386 and ppc platforms you need to call this line
    gcc -c -o SDLMain.o SDLMain.m -I /Library/Frameworks/SDL.framework/Headers
    with an additional --arch i386 or --arch ppc parameter depending on which platform you need.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  7. #7
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Sweet - so I guess this is solved now! Hooray!

    Quick note to apple: Windows users have functionality disabled in their versions of windows (unless you have ultimate). In your case, you either include functionality or you dont. For the next Mac OS X version - please include the functionality 'Common Sense' and 'Helpfulness'. I've never seen such a long thread for a simple linking issue. Apple: Pioneering in unexpected ways.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •