5

I have recently installed SFML 2.1 and am trying to compile and run from the terminal, NOT Xcode, the sample program that they have on their website at http://www.sfml-dev.org/tutorials/2.0/start-linux.php.

   Path to where I installed SFML:
   /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal

However, I keep getting the error of:

   Undefined symbols for architecture x86_64:
   "sf::String::String(char const*, std::__1::locale const&)", referenced from:
  _main in window-48cb4a.o

After googling it, I came across this question: SFML 2.1 RenderWindow linking error

In the accepted answer, the person said that if I wanted to use g++, I had to download the "GCC" version. So, I proceeded to download the GCC - universal 32+64 bits (OS X 10.5+) version and then followed the instructions for installing and compiling SFML on linux, since there were none for mac (http://www.sfml-dev.org/tutorials/2.0/start-linux.php) by doing the following:

Since I had installed SFML in a non-standard location, I told my compiler where to find the header files like so:

   -I /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/Frameworks/SFML.framework/Headers

I also had to tell my compiler where to find the SMFL libraries:

  -L /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib

I needed to also tell the library loader where to find the SFML libraries from:

  export LD_LIBRARY_PATH=/Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib

Then, I put the sfml-audio.framework, sfml-window.framework, sfml-graphics.framework, sfml-network.framework, and sfml-system.framework in my Frameworks directory (/Library/Frameworks).

Finally, I tried to compile my program in the following ways:

  1. g++ window.cpp -I /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/Frameworks/SFML.framework/Headers/SFML -L /users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib -framework sfml-graphics -framework sfml-window -framework sfml-system

  2. g++ window.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system

But, I keep getting the same error. I have continued to google the error, but all I keep getting are questions where people are using Xcode and not the terminal. Any help would be greatly appreciated!

4
  • Thank you very much, Joachim Pileborg, for editing my question! Commented Aug 21, 2014 at 22:16
  • It seems your pre-built SFML library was built using GCC (and its libstdc++), while you're using Clang (which uses libc++). Either try to find a pre-built version of SFML that was built with Clang and libc++, or download the source and build it yourself. And don't be fooled by you using the command g++ to build, it's actually clang++ being used. Commented Aug 21, 2014 at 22:16
  • I don't know how Darwin frameworks affect this, but usually to use a library with gcc/g++ you need a -l option to specify the library (the -L option just specifies a directory to search - the compiler/linker will not search all libraries in there, only specific libs). Commented Aug 21, 2014 at 22:22
  • Ah, interesting, I did not know that about g++. Is there something similar to g++ that I could use in order to correctly compile for what I have already without having to re-download SFML again? Commented Aug 21, 2014 at 22:23

1 Answer 1

4

I figured it out at last! First off, as Joachim Pileborg pointed out, I need to install the clang version of SFML for mac since I was using g++ to compile which is clang++ in disguise, as Joachim Pileborg also pointed out. Next, I had to go through the instructions again for setting up SFML with Linux (http://www.sfml-dev.org/tutorials/2.0/start-linux.php).

However, the icing on the cake was when I read this question:

OSX GCC how to specify sfml library source?

...and this question:

FreeType error when building in XCode

...which got me thinking: maybe I should try moving my freetype.framework folder (which can be found in the extlibs directory) into my /Library/Frameworks directory. Once I did this and compiled using

g++ window.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system

It compiled and ran successfully!!! I am very happy now!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.