0

Codeblocks version: 16.01 SFML version: 2.4.2

I created an SFML 2.0 project in Codeblocks. I selected New Project->SFML Project->SFML 2.0. I copied this code into the main.cpp file and compiled it.

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

When I built the code I got the following errors:

> -------------- Build: Debug in aaa (compiler: GNU GCC Compiler)---------------
> 
> mingw32-g++.exe -LC:\sfml\SFML-2.4.2\lib -o bin\Debug\aaa.exe
> obj\Debug\main.o   -lmingw32 -luser32 -lgdi32 -lwinmm -ldxguid
> C:\sfml\SFML-2.4.2\lib\libsfml-graphics.a
> C:\sfml\SFML-2.4.2\lib\libsfml-window.a
> C:\sfml\SFML-2.4.2\lib\libsfml-system.a -lsfml-graphics-s-d
> -lsfml-window-s-d -lsfml-system-s-d -lsfml-main-d obj\Debug\main.o: In function `main': C:/Users/my/Documents/codeblocks/aaa/main.cpp:5:
> undefined reference to `sf::String::String(char const*, std::locale
> const&)' C:/Users/my/Documents/codeblocks/aaa/main.cpp:5: undefined
> reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int,
> unsigned int)' C:/Users/my/Documents/codeblocks/aaa/main.cpp:5:
> undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode,
> sf::String const&, unsigned int, sf::ContextSettings const&)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:6: undefined reference
> to `sf::CircleShape::CircleShape(float, unsigned int)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:7: undefined reference
> to `sf::Color::Green' C:/Users/my/Documents/codeblocks/aaa/main.cpp:7:
> undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:15: undefined reference
> to `sf::Window::close()'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:12: undefined reference
> to `sf::Window::pollEvent(sf::Event&)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:18: undefined reference
> to `sf::Color::Color(unsigned char, unsigned char, unsigned char,
> unsigned char)' C:/Users/my/Documents/codeblocks/aaa/main.cpp:18:
> undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:19: undefined reference
> to `sf::RenderStates::Default'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:19: undefined reference
> to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates
> const&)' C:/Users/my/Documents/codeblocks/aaa/main.cpp:20: undefined
> reference to `sf::Window::display()'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:9: undefined reference
> to `sf::Window::isOpen() const'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:23: undefined reference
> to `sf::RenderWindow::~RenderWindow()'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:23: undefined reference
> to `sf::RenderWindow::~RenderWindow()' obj\Debug\main.o: In function
> `ZN2sf11CircleShapeD1Ev':
> C:/sfml/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined
> reference to `vtable for sf::CircleShape'
> C:/sfml/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined
> reference to `vtable for sf::CircleShape'
> C:/sfml/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined
> reference to `sf::Shape::~Shape()' collect2.exe: error: ld returned 1
> exit status Process terminated with status 1 (0 minute(s), 0
> second(s)) 20 error(s), 0 warning(s) (0 minute(s), 0 second(s))

I tried using both the static and dynamic versions without any success. What went wrong?

  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – alseether Oct 05 '17 at 08:16

1 Answers1

0

It turns out I was using the wrong version of SFML. I downloaded the GCC 4.7 TDM (SJLJ- 32-bit version and it worked.