SFML community forums

Help => General => Topic started by: esotericsean on May 17, 2013, 04:18:41 am

Title: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: esotericsean on May 17, 2013, 04:18:41 am
Hey everyone,

Really appreciate any help with this. I used to have 1.6 running in Code::Blocks back in the day. Now I have a Mac and am learning Xcode. I don't remember SFML being this complicated to install and get running, although I'm not the great programmer. Here is everything I did, please let me know where I went wrong:

1. Downloaded the latest FML 2.0 Source and "compiled" it with CMake and Xcode. Everything looked like it was successful. I used the CMake GUI.

2. Transferred the SFML templates into the correct folder and created a new SFML Project (C++98 with GCC and libstd++ and target 10.5).

3. Try to build and get the following errors:
(http://i.imgur.com/9wkty6k.png)

4. I've messed with build settings, linker settings, etc. but can't seem to figure out what exactly is wrong.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: eigenbom on May 17, 2013, 04:26:17 am
I always stumble on issues when building the mac version of my game. I always forget that on osx you have to compile for Unix target and explicitly specify the clang compiler to build the libs. I'm not sure if that's what's causing your problem though.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: esotericsean on May 17, 2013, 04:29:00 am
I might have built for Xcode. Let me try that.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: esotericsean on May 17, 2013, 04:48:54 am
Okay, so I used CMake and checked Unix Makefiles and specified the native compilers for C and C++ (/usr/bin/clang and /usr/bin/clang++, respectively).

This time, it didn't generate a project file for me to compile using Xcode. Instead, it generated a folder that looks like this:

(http://i.imgur.com/eqDJPij.png)

No clue what to do next. Doesn't look like there are any files for me to actually compile.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: eigenbom on May 17, 2013, 10:52:07 am
There are pre-built binaries, so you don't have to compile it yourself! See http://sfml-dev.org/tutorials/2.0/start-osx.php (http://sfml-dev.org/tutorials/2.0/start-osx.php)

But if you want to, then you can continue the process: open the Terminal, cd to that dir, and type "make install"
see here: http://sfml-dev.org/tutorials/2.0/compile-with-cmake.php (http://sfml-dev.org/tutorials/2.0/compile-with-cmake.php)
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Hiura on May 17, 2013, 11:24:47 am
as said by eigenbom, you don't need to compile SFML 2.0 yourself.. just download the binaries and follow the tutorials.

if you really want to compile it, read carefully the tutorial on cmake; it explicitly states that you should not attempt to compile SFML with Xcode but use Makefile instead.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: esotericsean on May 17, 2013, 07:21:58 pm
Thanks guys,

I was finally able to successfully compile it using Makefile. But projects still won't run by default in Xcode. Do I need to change the linker settings?

Here are the errors I'm getting: http://i.imgur.com/i6P3OjD.jpg (http://i.imgur.com/i6P3OjD.jpg)
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: eigenbom on May 18, 2013, 03:58:43 am
I remember I also had to change (in xcode build settings) from "standard c++ library" to "libstdc++" or some nonsense. Sorry I can't be of more help, I only ever build on mac once every 6 months. Good luck!
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: esotericsean on May 18, 2013, 08:11:50 am
I'll keep trying, thanks for your time.

Almost ready to give up on SFML and try something else. It's a shame, I really loved 1.6 and want to try working with 2.0
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Hiura on May 18, 2013, 04:06:10 pm
That statement is absolutely unfair ! The tutorial explicitly states how you have to set up the compiler flag to use clang/libc++ in your project. You clearly didn't read the documentation..

PLUS we provide already compiled binaries with some Xcode templates to ease the installation and creation of new projects.....
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: esotericsean on May 18, 2013, 09:04:34 pm
I'm sorry Hiura, I know you've put in a lot of work on this. I won't give up. :)

I'm not an expert programmer (my main job is video production), so the directions in the tutorial are hard for me to follow because I don't understand what all of it means. I have read it very thoroughly, several times, but I'm still having trouble.

I've tried both the already compiled binaries and also compiling them myself, both times I've run into linker errors. It works for some people, so I know that I'm doing something wrong -- I'm trying to take it step by step and figure it out.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Laurent on May 18, 2013, 09:07:06 pm
Quote
I'm not an expert programmer (my main job is video production), so the directions in the tutorial are hard for me to follow because I don't understand what all of it means.
Keep in mind that this is not our job to explain how to use your programming tools. And don't blame SFML for that, try to find good XCode tutorials instead :P
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Cornstalks on May 19, 2013, 01:21:35 am
I've tried both the already compiled binaries and also compiling them myself, both times I've run into linker errors. It works for some people, so I know that I'm doing something wrong -- I'm trying to take it step by step and figure it out.
I think the official tutorials are great, but in case it helps, I've got a short tutorial on building SFML 2 with Clang (and libc++) for C++11 (http://www.mjbshaw.com/2013/02/building-sfml-2-with-c11-on-os-x.html). Perhaps yet another resource might help just a little. If you do use my little tutorial, make sure that:

You have OS X 10.8.3
You have Xcode 4.6.2
Your system is all up to date
Your command line tools are up to date (Xcode -> Preferences -> Downloads will tell you if you need to download & install them (or update them)).
You pay very close attention to the last image in my tutorial and set everything exactly as I show it (of course, "Product Name," "Organization Name," and "Company Identifier" may be different).
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: esotericsean on May 19, 2013, 09:50:13 am
Thanks so much, Cornstalks!

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 (http://i.imgur.com/LGyLchh.jpg)

Any idea what that means? Thanks!

* * *

BTW, Laurent I know it's not your job to help me. Which is why I'm posting in your public forums for help, where hopefully other users can chime in. I understand if you personally don't have time. Appreciate it, though!
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Laurent on May 19, 2013, 11:14:31 am
Quote
BTW, Laurent I know it's not your job to help me. Which is why I'm posting in your public forums for help, where hopefully other users can chime in. I understand if you personally don't have time.
I like to help as much as I can on the forum, that was not my point. My point is that you shouldn't focus only on SFML and its tutorials if you don't know how to configure your projects, searching more general tutorials about XCode and how to link libraries could be helpful too -- and not only for SFML, but for all other libraries that you'll have to use in the future.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Cornstalks on May 19, 2013, 05:02:32 pm
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 (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.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: esotericsean on May 19, 2013, 08:06:14 pm
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 (http://i.imgur.com/OXcOQUZ.png)
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Cornstalks on May 19, 2013, 10:49:07 pm
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 (http://i.imgur.com/93ktdFU.jpg))
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Magtheridon96 on May 20, 2013, 12:43:08 am
I'm having this problem as well. Before I followed your tutorial Cornstalks, I followed Laurent's Tutorial (http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php). 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.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Cornstalks on May 20, 2013, 01:34:53 am
I'm having this problem as well. Before I followed your tutorial Cornstalks, I followed Laurent's Tutorial (http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php). 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 (http://en.sfml-dev.org/forums/index.php?topic=6162.0).

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...
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: Magtheridon96 on May 20, 2013, 08:24:03 pm
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.
Title: Re: All kinds of errors getting SFML 2 to run in Xcode, would appreciate some help.
Post by: sakydpozrux on June 14, 2013, 09:59:10 am
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.