Linker error with SFML

I am getting a series of startup errors in the g++ -lsfml-window -lsfml-graphics -lsfml-system main.cpp

SFML code example when starting Ubuntu, SFML 2.2 and g ++ 4.8.2. I tried reinstalling SFML from package manager ( libsfml-dev

) and nothing works.

Sample SFML code:

#include <SFML/Graphics.hpp>
#include <string>

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

      

Error message:

/tmp/ccVG6GjG.o: In function `main':
main.cpp:(.text+0xf7): undefined reference to `sf::String::String(char const*, std::locale const&)'
main.cpp:(.text+0x115): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text+0x148): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings cons'
main.cpp:(.text+0x182): undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
main.cpp:(.text+0x18e): undefined reference to `sf::Color::Green'
main.cpp:(.text+0x196): undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
main.cpp:(.text+0x1b6): undefined reference to `sf::Window::close()'
main.cpp:(.text+0x1cf): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text+0x1f7): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
main.cpp:(.text+0x214): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
main.cpp:(.text+0x22b): undefined reference to `sf::RenderStates::Default'
main.cpp:(.text+0x236): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
main.cpp:(.text+0x245): undefined reference to `sf::Window::display()'
main.cpp:(.text+0x254): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text+0x27f): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x2a9): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x2ee): undefined reference to `sf::RenderWindow::~RenderWindow()'
/tmp/ccVG6GjG.o: In function `sf::CircleShape::~CircleShape()':
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x13): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x1f): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x2b): undefined reference to `sf::Shape::~Shape()'
collect2: error: ld returned 1 exit status

      

+3


source to share


2 answers


There are two ways to solve this problem. The first is the replacement of certain parameters, so the team will be as follows: g++ main.cpp -lsfml-window -lsfml-graphics -lsfml-system

. The second option is to try updating g ++ to version 4.9.2, which can be achieved on ubuntu by doing this



+4


source


clang ++ - 3.6 ( clang-3.6 LLVM based package ) works for me and is part of the package repo. g ++ - 4.8.2 did not work with reordering libs.



0


source







All Articles