How to get SMFL to work on windows using clion
Published: 2023-03-28 15:43:54



1.Go to https://7-zip.org/download.html and download the 64 bit version or 32 bit if that's how your PC/laptop is running.

2.These next parts have to be done so this can work correctly with cmake. Go to https://www.sfml-dev.org/download/sfml/2.5.1/ and download both these files.

If you like to see any image copy and paste the link to see through out this post.


https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhioary616y8peq114i1.PNG

https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1aw5tdgcy5yby5sh6xuu.PNG


3.It does not matter if you have minGW already installed it is a more updated version so it won’t work(version 9.0) so the SFML website links you to download the 64 bit 6.0 version.

4.Then go to download and install 7 zip then unzip both file you installed from sfml and extract files like in this picture make sure you do it in downloads or you won’t be able to do it because of permissions if this happens try “Extract here” options from 7 zip.

https://dev-to-uploads.s3.amazonaws.com/uploads/articles/too7t0vl2lllgpv2miyq.jpg

5.After both the minGW and sfml files have been extracted click once into each file and cut or move the file to your main disk of your laptop/PC make sure you move the folder inside of the folder you downloaded so the paths can be correct later.


https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8r4hbyrzc89efg17pna.PNG


6.Then remember the name of the minGW(most likely mingw64) compiler you downloaded and rename the SFML2.5.1 folder to SFML will make our lives easier later.

7.Open a project if you name it minesweeper you can copy the code for Cmake directly and now we have to check or change the minGW clion is working on so CRTL+ALT+S in clion to get to settings go to Build, Execution, Deployment tab then inside of that click on toolchains and change your Toolset to the mingw64 or whatever you named it so clion can start using it and apply and press ok.


https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ct51j1fk17lbk4baylvm.PNG

8.Almost done in your project make a main.cpp and configure cmake. Then after that is done go to CMakeLists.txt to add the sfml library and copy and paste this code exactly it is very specific.



cmake_minimum_required(VERSION 3.24)
project(minesweeper)


set(CMAKE_CXX_STANDARD 14)


add_executable(minesweeper main.cpp)


set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR C:/SFML/lib/cmake/SFML)
find_package(SFML COMPONENTS system window graphics audio network REQUIRED)


include_directories(c:/SFML/include/SFML)
target_link_libraries(minesweeper sfml-system sfml-window sfml-graphics sfml-audio)





9.If you didn’t name the folder minesweeper replace minesweeper in the code above to whatever the name of you folder is.


10.Then reload your cmake to update the changes and go to you main to test that it works and copy and paste this basic program to see if it works.



#include <SFML/Graphics.hpp>
where it saids include in bold look at the picture to see what goes there because doesn't allow <> form some reason.
https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wcqyhj5kdcmdqdbqspf5.PNG

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;
}



11.Run the program and a small green dot sure pop up on your screen. If it didn’t ethier you have the wrong version of mingGW or named something wrong.