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

Author Topic: Please update the SFML OS X tutorial for C++11  (Read 7182 times)

0 Members and 1 Guest are viewing this topic.

Cornstalks

  • Full Member
  • ***
  • Posts: 180
    • View Profile
    • My Website
Please update the SFML OS X tutorial for C++11
« on: January 25, 2013, 03:24:48 am »
I was following the tutorial for making SFML with C++11 support, but I kept getting linker errors with anything that used anything from the standard library. The one thing I had to add that wasn't in the tutorial was setting CMAKE_C_FLAGS to be stdlib=libc++ too (not just CMAKE_CXX_FLAGS).

This is exactly how I had to do it:
export CMAKE_OSX_ARCHITECTURES=i386;x86_64

cd <sfml folder>

mkdir build

cd build

cmake -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER=/usr/bin/clang -DSFML_BUILD_FRAMEWORKS=ON \
-DSFML_INSTALL_XCODE4_TEMPLATES=ON \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_C_FLAGS="-stdlib=libc++" ../

make -j8

sudo make install
 

Notice the -DCMAKE_C_FLAGS="-stdlib=libc++" at the end. Without it, I kept getting the following errors when making an Xcode project that used clang & libc++ for C++11 support:

Undefined symbols for architecture x86_64:
  "sf::RenderWindow::RenderWindow(sf::VideoMode, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, sf::ContextSettings const&)", referenced from:
      _main in main.o
  "sf::Font::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in main.o
  "sf::Image::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in main.o
  "sf::Music::openFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in main.o
  "sf::String::String(char const*, std::__1::locale const&)", referenced from:
      _main in main.o
  "sf::Texture::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sf::Rect<int> const&)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 

Hopefully I'm not crazy...

Also, thanks for SFML! I'm really looking forward to 2.0's official release (and then I'm really looking forward to 2.x when OpenGL ES 2.0 is supported!)
« Last Edit: January 25, 2013, 03:26:51 am by Cornstalks »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Please update the SFML OS X tutorial for C++11
« Reply #1 on: January 25, 2013, 09:13:10 am »
Interesting.. it works perfectly on my machine with CXX only. What OS X version and Xcode version do you have ?

Anyway, I guess adding this to the tutorial won't kill somebody. Thanks for the notice.
SFML / OS X developer

Cornstalks

  • Full Member
  • ***
  • Posts: 180
    • View Profile
    • My Website
Re: Please update the SFML OS X tutorial for C++11
« Reply #2 on: January 25, 2013, 02:56:46 pm »
Interesting.. it works perfectly on my machine with CXX only. What OS X version and Xcode version do you have ?
Sorry, I should've included that. OS X 10.8.2 and Xcode 4.5.2. Note that I don't have macports. Clang version:
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.1
Thread model: posix
 

I've also never installed SFML on this machine.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Please update the SFML OS X tutorial for C++11
« Reply #3 on: January 25, 2013, 03:01:36 pm »
That's even more weird : I got the same versions and it works..  ???

but I'll do the change anyway.
SFML / OS X developer

Cornstalks

  • Full Member
  • ***
  • Posts: 180
    • View Profile
    • My Website
Re: Please update the SFML OS X tutorial for C++11
« Reply #4 on: January 25, 2013, 04:34:58 pm »
That's even more weird : I got the same versions and it works..  ???

but I'll do the change anyway.
If this gets any weirder: when I use ccmake I get stuck in an infinite loop in ccmake. For example, if I do:

ccmake -G "Unix Makefiles" ..
... set the following:
CMAKE_CXX_COMPILER = /usr/bin/clang++
CMAKE_CXX_FLAGS = -stdlib=libc++
CMAKE_C_COMPILER = /usr/bin/clang
SFML_BUILD_FRAMEWORKS = ON
SFML_INSTALL_XCODE4_TEMPLATES = ON
 

(and then hit "c" to configure) It just keeps flashing something about glew in an infinite loop... Setting those ops from the command line and just using cmake works though.

Edit: Also, I have cmake version 2.8.10.1
« Last Edit: January 25, 2013, 05:41:43 pm by Cornstalks »

ThePenguinn

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Please update the SFML OS X tutorial for C++11
« Reply #5 on: June 28, 2013, 04:08:23 am »
I have been getting the same errors and i just got SFML today 2.0. Where is this file that i have to edit to get this to work?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Please update the SFML OS X tutorial for C++11
« Reply #6 on: June 28, 2013, 08:11:48 am »
Please open a new thread next time. Perhaps give a link to an old thread but keep things separated – it's easier in fact for other people to understand what's going.  ;)

just got SFML today 2.0.

How exactly? From the download page, so as a pre-compiled package, or from github, so you compiled it yourself?
SFML / OS X developer

ThePenguinn

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Please update the SFML OS X tutorial for C++11
« Reply #7 on: June 28, 2013, 05:41:32 pm »
I got it from the downloads page. I use Xcode and I got the one that had the c++11 support and lib...something. I also installed it the frameworks way.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Please update the SFML OS X tutorial for C++11
« Reply #8 on: June 28, 2013, 05:44:33 pm »
And when you configured your project with the wizard, you carefully selected the C++11 option?
SFML / OS X developer

ThePenguinn

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Please update the SFML OS X tutorial for C++11
« Reply #9 on: June 28, 2013, 06:21:06 pm »
WOW! God that was silly I used the c++98 with lib in the wizard let me see now if it works. Thank You!

Update: Yup it works thank you! next time ill make a new thread.
« Last Edit: June 28, 2013, 06:23:41 pm by ThePenguinn »