- XCode needs to be installed to get compilers first (ie. clang, g++). It can be installed via AppStore.
- You need sfml library which you can get the one I uploaded to this repository(v2.6.1)
$ git clone https://github.com/cakirburak/SFML-Setup-on-MacOS.git
- Go into the sfml library
$ cd SFML-Setup-on-MacOS/sfml/2.6.1/
- Copy the sfml libraries to the folder where standard libraries are;
$ sudo cp -r lib/* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
- Copy the sfml includes to the folder where standard includes are;
$ sudo cp -r include/* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
After completing these steps you are ready to go!
- Create a file named
main.cpp
and get the code below
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
- Compile and Run
$ g++ main.cpp -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
$ ./sfml-app