Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.  (Read 12579 times)

0 Members and 1 Guest are viewing this topic.

Cornstalks

  • Full Member
  • ***
  • Posts: 180
    • View Profile
    • My Website
Followed your tutorial to the tee, but I'm getting one error: "Shell Script Invocation Error, Command /bin/sh failed with exit code 2"

Here's a screenshot: http://i.imgur.com/LGyLchh.jpg
I'm assuming that's the project you made after building to test SFML (and you did it exactly how my "Bonus Step" shows, right?). When you created this project, you did say you were going to use frameworks, right?

Any idea what that means?
There's a custom shell script file that runs after building SFML to copy the required dylibs/frameworks into the application bundle. For some reason though, it's complaining about it. Open the shell script file and post the first 15 lines of code (it tells you the path to it... it's a really long one: "/Users/esotericsean/Library/Developer/Xcode/DerivedData/SFML_C++11_.../<lost more junk>/***.sh" just copy that file path, open a terminal, and say "open <paste script file path>"). I just want to make sure they're right and didn't get screwed up.

Also, go to your project's build settings and tell me what the value of "SFML_BINARY_TYPE" is.

esotericsean

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://seanduran.com
Really appreciate it Cornstalks.

I did use Universal and Franeworks when setting up the project.

Opened that .sh file and it opened up in Xcode, here's what's in it:

Quote
#!/bin/sh
# This shell script simply copies required sfml dylibs/frameworks into the application bundle frameworks folder.
# If you're using static libraries (which is not recommended) you should remove this script from your project.

# Are we building a project that uses framework or dylibs ?
case "$SFML_BINARY_TYPE" in
    DYLIBS)
        frameworks="false"
        ;;
    *)
        frameworks="true"
        ;;
esac

# Echoes to stderr
error () # $* message to display
{
    echo $* 1>&2
    exit 2
}

assert () # $1 is a boolean, $2...N is an error message
{
    if [ $# -lt 2 ]
    then
        error "Internal error in assert : not enough args"
    fi

    if [ $1 -ne 0 ]
    then
        shift
        error "$*"
    fi
}

force_remove () # $1 is a path
{
    test $# -eq 1
    assert $? "force_remove() requires one parameter"
    rm -fr "$1"
    assert $? "couldn't remove $1"
}

copy () # $1 is a source, $2 is a destination
{
    test $# -eq 2
    assert $? "copy() requires two parameters"
    ditto "$1" "$2"
    assert $? "couldn't copy $1 to $2"
}

require () # $1 is a SFML module like 'system' or 'audio'
{
    dest="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Contents/Frameworks"
   
    if [ -z "$1" ]
    then
        error "require() requires one parameter!"
    else
        # clean potentially old stuff
        force_remove "$dest/libsfml-$1.2.dylib"
        force_remove "$dest/libsfml-$1-d.2.dylib"
        force_remove "$dest/sfml-$1.framework"
   
        # copy SFML libraries
        if [ "$frameworks" = "true" ]
        then
            copy "/Library/Frameworks/sfml-$1.framework" "$dest/sfml-$1.framework"
        elif [ $CONFIGURATION = "Debug" ] && [ $SFML_LINK_DYLIBS_SUFFIX_DEBUG != "" ]
        then
            copy "/usr/local/lib/libsfml-$1-d.2.dylib" "$dest/libsfml-$1-d.2.dylib"
        else
            copy "/usr/local/lib/libsfml-$1.2.dylib" "$dest/libsfml-$1.2.dylib"
        fi
       
        if [ "$1" = "audio" ]
        then
            # copy sndfile framework too
            copy "/Library/Frameworks/sndfile.framework" "$dest/sndfile.framework"
        fi

        if [ "$1" = "graphics" ]
        then
            # copy freetype framework too
            copy "/Library/Frameworks/freetype.framework" "$dest/freetype.framework"
        fi
    fi
}

if [ -n "$SFML_SYSTEM" ]
then
    require "system"
fi

if [ -n "$SFML_AUDIO" ]
then
    require "audio"
fi

if [ -n "$SFML_NETWORK" ]
then
    require "network"
fi

if [ -n "$SFML_WINDOW" ]
then
    require "window"
fi

if [ -n "$SFML_GRAPHICS" ]
then
    require "graphics"
fi

SFML_BINARY_TYPE is set to FRAMEWORKS, screenshot: http://i.imgur.com/OXcOQUZ.png

Cornstalks

  • Full Member
  • ***
  • Posts: 180
    • View Profile
    • My Website
Honestly, I'm puzzled. That's what it should be. The errors are complaining about line 4 (which is blank) and line 6 (which is fine)... It's really hard to say.

The only suggestion I can really make is cleaning the project (Product -> Clean) and then rebuilding (Product -> Build). After doing that, look at all the logs and make sure everything was successful (here's how to look at logs in detail)

Magtheridon96

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
I'm having this problem as well. Before I followed your tutorial Cornstalks, I followed Laurent's Tutorial. I was trying to statically link SFML, but I was getting about 200 linker errors related to the FreeType library. Some of them were related to the GLEW library.

Anyway, that's not my point here. I want to know if anyone has been successful in getting SFML to work with Xcode. (Other than the people in this thread who seem to have it working already)

I need to assure myself that /I/ am doing something wrong so I can fix the problem.

Cornstalks

  • Full Member
  • ***
  • Posts: 180
    • View Profile
    • My Website
I'm having this problem as well. Before I followed your tutorial Cornstalks, I followed Laurent's Tutorial. I was trying to statically link SFML, but I was getting about 200 linker errors related to the FreeType library. Some of them were related to the GLEW library.
Don't statically link to SFML on OS X.

Gee, people seem to have weird issues with SFML on OS X. A few people on my blog have said they had issues with the FreeType framework. I'm considering making a video tutorial now...

Magtheridon96

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
For some very odd reason, all I did was wait a day and it somehow worked when I attempted to recompile it. Maybe a system restart is required in between one of the steps perhaps?

Edit:
Okay, I figured it out. In order to fix that error concerning the shell script, all you need to do is restart Xcode.
« Last Edit: May 20, 2013, 10:22:52 pm by Magtheridon96 »

sakydpozrux

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Thank you for your help. After following tutorials I had an "Shell Script Invocation Error, Command /bin/sh failed with exit code 2". I had to restart Xcode to make things work and It seems to be OK now.

Edit:
There was a line about editing problematic .sh file, but editing it seems not to change anything. Restarting Xcode is enough.
« Last Edit: June 14, 2013, 11:01:14 am by sakydpozrux »