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

Author Topic: Setting up SFML Xcode on M1 or M2  (Read 1073 times)

0 Members and 1 Guest are viewing this topic.

antinoid

  • Newbie
  • *
  • Posts: 8
    • View Profile
Setting up SFML Xcode on M1 or M2
« on: December 17, 2022, 08:03:43 pm »
This is a post that goes over how I set up SFML on my M2 MacBook pro running Ventura 13.0.1 and got it working on Xcode version 14.0.1.

I spent a week combing through videos and forum posts trying to figure this out so this post should hopefully help others not to have to waste as much time as I did XD.

To start off, make sure to download Xcode. I downloaded it from AppStore. so should be pretty easy for you to do. (if you can't figure out how to download something from the AppStore... welp)

Next, we want to download SFML, currently, the main version of SFML, WILL NOT work on your M1 or M2 mac so we want to use one of the snapshot versions.
This can be done by going to the SFML website, clicking "download" then selecting "snapshots", (or go to this link: https://artifacts.sfml-dev.org/by-branch/master/)
Now the snapshot I downloaded was the "macos-clang-arm64.tar.gz" (make sure it's arm64).

Now copy all the .framework folders you downloaded (it's a couple of folders deep) into "Library/Frameworks/"

(if you struggling to find "Library/Frameworks/" open a finder window and press "command"+"," the sidebar, then check the "Hard Disks" option, now your root folder should appear on your sidebar in finder)

Your frameworks folder (in "Library/Frameworks") should look like the image I have attached.
You might have other framework files like a python one or whatnot but that's COMPLETELY FINE, DON'T DELETE any of the files that were already in the folder.

Next open Xcode and create a new terminal application (I am not using the SFML templates for this example, I couldn't get them working so just an empty project)

Open up Xcode project options and go to the "general" tab, under "frameworks and libraries" click the little "+" and under "add other", click "add files..." now locate the "Library/Frameworks" folder and select the following options:
sfml-graphics.framework
sfml-system.framework
sfml-window.framework

once you've done that, go to the "Build Phases" tab and under "Link Binary with Libraries" do the same thing.

now go to the main.cpp file and copy the following test code into it:

#include <SFML/Graphics.hpp>

int main(int argc, const char * argv[]) {
   
    sf::RenderWindow window(sf::VideoMode(sf::Vector2u(200, 200)), "Title");
   
    sf::RectangleShape rect;
    rect.setSize(sf::Vector2f(100, 100));
    rect.setFillColor(sf::Color::Red);
    rect.setPosition(sf::Vector2f(50, 50));

   
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if(event.type == sf::Event::Closed)
                window.close();
        }
       
        window.clear();
        window.draw(rect);
        window.display();
    }
}


Now run the program, if it's working you should get a popup error that says something along the lines of "sfml-graphics.framework is broken and can't be run" if you get this pop-up then do the following:

open up a new terminal window, paste the command "cd /Library/Frameworks " and you should get routed into the frameworks folder.

What the error means is that your computer is blocking the frameworks form running for security, so we want to tell the computer that it's allowed to run. (btw you can check the framework by running "ls -l@ <framework name>") to allow each framework we want to run the command

"sudo xattr -d com.apple.quarantine <name of framework>"

where <name of framework> is one of the folders (e.g. sfml-graphics.framework or sfml-window.framework)

now you want to do this command for every framework you copied over, it might take a bit but once you've finished you should be able to run the program and see a window pop up with a red square in it.

That's how I got this working, if you have any suggestions on how this post could be made better or if you want to expand on how to use the templates please do.
« Last Edit: December 17, 2022, 08:05:51 pm by antinoid »

 

anything