Search code examples
c++codeblockslibrariessfml

SFML tutorial not even working


I installed SFML on codeblocks with their tutorial, following it step by step. Everything has been checked and done correctly, yet their sample program is not even building correctly. It seems that codeblocks cannot even find the basic functions of SFML. What did I miss?

Error log :

( https://i.sstatic.net/RlNcL.jpg )

My code :

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

Solution

  • It's very strange to give a library location -L and then explicitly link to the exact library. So, instead of giving the full path to the library, just give it's name. So, instead of ..\..\..\..\..\LOGICIELS\CodeBlocks\SFML\libs\libsfml-graphics-s-d.a just say sfml-graphics-s-d. Do this for all libraries

    When you see -L..\..\..\..\..\..\LOGICIELS\CodeBlocks\SFML\lib you are telling the compiler (linker) where to find the libraries. The convention with libraries is that they are prefaced with lib and followed by .a. So, change you library linkage to just the name of your library, sans lib and .a

    so, after obj\Debug\main.o, it should be sfml-grphics-s-d sfml-window-a-d sfml-system-a-d sfml-main-d