Set up SFML with CodeBlocks step by step tutorial

7555
views

Download SFML – GCC 4.7.1 TDM (SJLJ) – 32-bit:

http://www.sfml-dev.org/download/sfml/2.3/

01

02

Extract archive and move SFML-2.3 folder to C:\

03

04

 

 

Download Codeblocks – codeblocks-13.12mingw-setup.exe:

http://www.codeblocks.org/downloads/26

05

 

 

Install CodeBlocks and go to Settings/Compiler/Reset defaults

06

 

 

Create new Empty project in CodeBlocks:

07

08

09

 

 

For this tutorial name of the project will be “Project”.

10

11

12

 

 

Open Project Built Options

13

 

 

Click on your project name “Project” .

14

 

 

In Project/Linker settings/Link libraries click on “Add” and add “sfml-graphics”, “sfml-window” and “sfml-system”.

15

 

 

In Project/Search directories/Compiler click on Add and add “C:\SFML-2.3\include”.

16

 

 

In Project/Search directories/Linker add “C:\SFML-2.3\lib”.

17

 

 

Go to Debug:

18

 

 

In Debug/Linker settings/Link libraries click on “Add” and add “sfml-graphics”, “sfml-window” and “sfml-system”.

19

 

 

In Debug/Search directories/Compiler add “C:\SFML-2.3\include”.

20

 

 

In Debug/Search directories/Linker add “C:\SFML-2.3\lib”.

21

 

 

Go to Release:

22

 

 

In Release/Linker settings/Link libraries add “sfml-graphics”, “sfml-window” and “sfml-system”.

23

 

 

In Release/Search directories/Compiler add “C:\SFML-2.3\include”.

24

 

 

In Release/Search directories/Linker add “C:\SFML-2.3\lib”. Click OK.

25

 

 

Create new C++ file and name it main.cpp

26

27

28

29

30

31

 

 

Add this code in main.cpp:

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

32

 

 

Click on Build/Build to build the project.

33

34

 

 

Go to C:\SFML-2.3\bin and copy all .dll files:

35

 

 

Go to C:\Project\bin\Debug and paste .dll files:

36

 

 

Go to C:\Program Files (x86)\CodeBlocks\MinGW\bin and copy:

libgcc_s_sjlj-1.dll

libstdc++-6.dll

37

 

 

Go to C:\Project\bin\Debug and paste:

libgcc_s_sjlj-1.dll

libstdc++-6.dll

38

 

 

Click on Project Application to see if its working:

39

 

 

If everything works you should see this:

40