skip to Main Content

I installed SFML for macOS-clang with this video https://www.youtube.com/watch?v=WOyp5n2FmZY. And I setup the Xcode like this video https://www.youtube.com/watch?v=kusRtYC-wj4 but it does not work like in the video. It can be built with no error or warning but when I run this is what happen. Just so you guys know that

  1. I am an amateur.
  2. I use MacBook Pro M1 2020.
  3. I never work with SFML before.
  4. I just start using Xcode. I am used to work on VSCode before.
  5. I got Rosetta2 installed.
  6. Before this I have tried to do it on VSCode with this Boilerplate(https://github.com/andrew-r-king/sfml-vscode-boilerplate.git).
  7. I also have tried SFML that install via Homebrew.

What should I do? I really need to do this because I have to use it to make my game project for my college. Thank you all in advance.

2

Answers


  1. First, install SFML with brew.

    brew install sfml
    

    Get location information

    brew info sfml
    

    You will see /opt/homebrew/Cellar/sfml/2.X.Y in the output. It is the location for headers, lib, etc.

    Compile with

    g++ main.cpp -I/opt/homebrew/Cellar/sfml/2.5.1_1/include -o app -L/opt/homebrew/Cellar/sfml/2.5.1_1/lib -lsfml-graphics -lsfml-window -lsfml-system
    

    Last step is:

    ./app
    

    Done!

    #include <SFML/Graphics.hpp>
    
    int main()
    {
        sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Application");
        sf::CircleShape shape;
        shape.setRadius(40.f);
        shape.setPosition(100.f, 100.f);
        shape.setFillColor(sf::Color::Cyan);
    
        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();
        }
    }
    
    Login or Signup to reply.
  2. For M1 macs

    1. setup all the paths:

    Header Search Paths
    Libary Search Paths

    You can add the path to the homebrew installation.

    1. Pay attention for what MacOS version you are building. For MacOS 11.0 and bellow, the only option is to use rosetta…

    2. If your mac has a AppleSilicon, installing sfml with brew will generate arm64 libraries for you. So will need to update the MacOS version in your project and choose the correct test platform in the upper bar, inside Xcode, you should have MyProject > My Mac (Rosetta) or MyProject > My Mac, just Choose "My Mac" if you are using brew.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search