Skip to content

Instantly share code, notes, and snippets.

@djpeach
Last active March 20, 2023 15:33
Show Gist options
  • Save djpeach/4b580efb98ecbac3208e7b66660f6756 to your computer and use it in GitHub Desktop.
Save djpeach/4b580efb98ecbac3208e7b66660f6756 to your computer and use it in GitHub Desktop.

DO NOT skip the MinGW or SFML steps, but any other steps you should be fine to skip as long as you have done them before. I don't recommend it though. For example, you may want to uninstall CMake and reinstall it, etc.

Install Git Bash

  • From here: https://git-scm.com/download/win
  • Run, and proceed throught install steps Be sure to select the option "Use Git and optional Unix tools from Command Prompt"
  • Do not change any other values
  • Git Bash will henceforth be called the terminal
  • Pin Git Bash to taskbar

Install 7zip

Install MinGW

check that you do not have a C:\MinGW folder already. If you do, delete it

Optional Test:

  • create a main.cpp file:
#include <iostream>

int main() { 
  std::cout << "hello world" << std::endl;
}
  • Open the terminal and run
g++ main.cpp
./a.exe
  • You should see "hello world" printed out. If not, stop and figure out why it is not working.

Install CMake

Optional Test:

  • Delete your old a.exe
  • Create a simple CMakeLists.txt:
cmake_minimum_required(VERSION 3.7)

add_executable(test main.cpp)
  • Open the terminal and run cmake -G "MinGW Makefiles" .

If you get an error referencing that you cannot have sh.exe in your path, look at where it is telling you that sh.exe is at, go there, and delete it. Idk what it does but it has not affected me yet so... ¯_(ツ)_/¯

  • You should get a Makefile generated
  • Run make

If you get an error referencing that make is not a recognized command, install it here: http://gnuwin32.sourceforge.net/downlinks/make.php, then add that bin/ folder to your path as well

  • Run ./text.exe
  • You should see "hello world" printed out. If not, stop and figure out why it is not working.

Install SFML

Again, make sure the folder C:\SFML now contains the bin folder. if it contains the SFML-2.5.1... folder instead, go into that folder, into the SFML folder, and copy all the folders in there. Then paste them in the parent of C:\SFML. Then delete the SFML-2.5.1.. folder completely

  • Add C:\SFML\bin to your PATH
  • Add a new Environment Variable as CPLUS_INCLUDE_PATH and set it equal to C:\SFML\include\SFML

Final Test!

  • Delete any previous files from testing
  • The main.cpp file:
#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(400, 400), "test window");

    while(window.isOpen()) {
        sf::Event event;

        while(window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }

        window.clear();

        // Draw stuff here later ...

        window.display();
    }
}
  • The CMakeLists.txt file:
cmake_minimum_required(VERSION 3.1)

project(test)

set(SFML_DIR "C:/SFML/lib/cmake/SFML")

find_package(SFML 2.5.1 COMPONENTS system window graphics audio network REQUIRED)

add_executable(test main.cpp)

target_link_libraries(test sfml-system sfml-window sfml-graphics sfml-audio sfml-network )
  • Go to where these files are with your terminal and run:
cmake -G "MinGW Makefiles" .
make
./test.exe
  • You should see a small black window pop up, and be able to 'X' out. If not, figure out what is wrong
@ghulam2545
Copy link

gcc 6.x.x is not working with SFML 2.5.1 so I have switched to 12.2.0, now it's fine.
May be it will be helpful for others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment