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!)
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.
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