SFML community forums

Help => General => Topic started by: Chi on July 19, 2013, 03:18:36 pm

Title: Eclipse / Makefile / Linux -> Errors ?
Post by: Chi on July 19, 2013, 03:18:36 pm
Hello all,

i want to run SFML2 in Eclipse under Linux.  I Just start a new Eclipse empty Makefile C++ Project.
All SFML includes and libs are installed in the standardpath.

Makefile
Code: [Select]
LIBS = -lsfml-graphics -lsfml-window -lsfml-system

all: hello

clean:
rm main.o hello

hello: main.o
g++ -g -o hello main.o

main.o:
g++ -c -g main.cpp

main.cpp
Code: [Select]
#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;
}

i klick Build all:
Code: [Select]
15:16:47 **** Incremental Build of configuration Default for project testSFML ****
make all
g++ -g -o hello main.o
main.o: In function `main':
/home/boo/dev/workspace/testSFML/main.cpp:5: undefined reference to `sf::String::String(char const*, std::locale const&)'
/home/boo/dev/workspace/testSFML/main.cpp:5: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/home/boo/dev/workspace/testSFML/main.cpp:5: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/home/boo/dev/workspace/testSFML/main.cpp:6: undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
/home/boo/dev/workspace/testSFML/main.cpp:7: undefined reference to `sf::Color::Green'
/home/boo/dev/workspace/testSFML/main.cpp:7: undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
/home/boo/dev/workspace/testSFML/main.cpp:15: undefined reference to `sf::Window::close()'
/home/boo/dev/workspace/testSFML/main.cpp:12: undefined reference to `sf::Window::pollEvent(sf::Event&)'
/home/boo/dev/workspace/testSFML/main.cpp:18: undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
/home/boo/dev/workspace/testSFML/main.cpp:18: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
/home/boo/dev/workspace/testSFML/main.cpp:19: undefined reference to `sf::RenderStates::Default'
/home/boo/dev/workspace/testSFML/main.cpp:19: undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/home/boo/dev/workspace/testSFML/main.cpp:20: undefined reference to `sf::Window::display()'
/home/boo/dev/workspace/testSFML/main.cpp:9: undefined reference to `sf::Window::isOpen() const'
/home/boo/dev/workspace/testSFML/main.cpp:23: undefined reference to `sf::RenderWindow::~RenderWindow()'
/home/boo/dev/workspace/testSFML/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/home/boo/dev/workspace/testSFML/main.cpp:23: undefined reference to `sf::RenderWindow::~RenderWindow()'
main.o: In function `sf::CircleShape::~CircleShape()':
/usr/local/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/local/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/local/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `sf::Shape::~Shape()'
collect2: Fehler: ld gab 1 als Ende-Status zurück
make: *** [hello] Fehler 1

15:16:47 Build Finished (took 203ms)

Does anybody know what i do wrong ?
Title: Re: Eclipse / Makefile / Linux -> Errors ?
Post by: eXpl0it3r on July 19, 2013, 03:40:42 pm
If you build in debug mode (gcc -g) then you'll have to link the debug libraries (sfml-xyz-d) and not the release ones (sfml-xyz), as written in the tutorial. :)
Title: Re: Eclipse / Makefile / Linux -> Errors ?
Post by: Laurent on July 19, 2013, 03:48:11 pm
Your LIBS variable is not used in the makefile.
Title: Re: Eclipse / Makefile / Linux -> Errors ?
Post by: Chi on July 19, 2013, 09:22:20 pm
First, thank you for fast answers.

I delete the debug -g option

Code: [Select]
LIBS = -lsfml-graphics -lsfml-window -lsfml-system

all: hello

clean:
rm main.o hello

hello: main.o
g++ -o hello main.o

main.o:
g++ -c main.cpp

But it is still not working. I dont know what is exactly the problem (alredy bought a book about make but it is not arrived ^^).

Is there still sth. not ok ?

Code: [Select]
21:23:04 **** Incremental Build of configuration Default for project testSFML ****
make all
g++ -o hello main.o
main.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 const&)'
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+0x1b4): undefined reference to `sf::Window::close()'
main.cpp:(.text+0x1cd): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text+0x1f5): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
main.cpp:(.text+0x212): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
main.cpp:(.text+0x229): undefined reference to `sf::RenderStates::Default'
main.cpp:(.text+0x234): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
main.cpp:(.text+0x243): undefined reference to `sf::Window::display()'
main.cpp:(.text+0x252): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text+0x27d): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x2ac): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x2f2): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.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: Fehler: ld gab 1 als Ende-Status zurück
make: *** [hello] Fehler 1
Title: Re: Eclipse / Makefile / Linux -> Errors ?
Post by: Chi on July 19, 2013, 09:31:14 pm
Your LIBS variable is not used in the makefile.

How you meen that :) ?
Did i must it write different ?
Title: AW: Eclipse / Makefile / Linux -> Errors ?
Post by: eXpl0it3r on July 19, 2013, 09:40:49 pm
You only define LIBS but you don't use it. Add $(LIBS) at the end of the build command (I think).
Title: Re: Eclipse / Makefile / Linux -> Errors ?
Post by: Chi on July 19, 2013, 09:48:10 pm
Thank you ! That works.

The last Problem is just now that the application who is compiled is not starting automaticly in Eclipse when i press "Build & Run"
Title: AW: Eclipse / Makefile / Linux -> Errors ?
Post by: eXpl0it3r on July 19, 2013, 10:03:24 pm
Does exclipse really work with make files? You might want to read up on some Eclipse documentation  ;)
Title: Re: AW: Eclipse / Makefile / Linux -> Errors ?
Post by: Chi on July 19, 2013, 10:15:39 pm
Does exclipse really work with make files? You might want to read up on some Eclipse documentation  ;)

I Think that. You can choose by "create project"  a empty makefile project or a autogenerated makefile project ... :x
and if w write only a console application, it works well.