Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Makefile issue!?  (Read 2002 times)

0 Members and 1 Guest are viewing this topic.

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Makefile issue!?
« on: September 12, 2015, 05:58:10 pm »
#define SFML_STATIC
// this is 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;
}

this is the makefile:
INCLUDE = -Iinclude
LIB = -Llib -lsfml-graphics-s -lfreetype -ljpeg -lsfml-window-s -lopengl32 -lgdi32 -lsfml-system-s -lwinmm

all: main.o
        g++ $(LIB) main.o -o bin\\coe.exe

clean:
        -del *.o
        -del bin\\coe.exe

main.o: main.cpp
        g++ $(INCLUDE) -c main.cpp

error:
g++ -Llib -lsfml-graphics-s -lfreetype -ljpeg -lsfml-window-s -lopengl32 -lgdi32
 -lsfml-system-s -lwinmm main.o -o bin\\coe.exe
main.o:main.cpp:(.text+0x120): undefined reference to `sf::String::String(char c
onst*, std::locale const&)'
main.o:main.cpp:(.text+0x14e): undefined reference to `sf::VideoMode::VideoMode(
unsigned int, unsigned int, unsigned int)'
main.o:main.cpp:(.text+0x19a): undefined reference to `sf::RenderWindow::RenderW
indow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&
)'
main.o:main.cpp:(.text+0x1e2): undefined reference to `sf::CircleShape::CircleSh
ape(float, unsigned int)'
main.o:main.cpp:(.text+0x1f2): undefined reference to `sf::Color::Green'
main.o:main.cpp:(.text+0x203): undefined reference to `sf::Shape::setFillColor(s
f::Color const&)'
main.o:main.cpp:(.text+0x229): undefined reference to `sf::Window::close()'
main.o:main.cpp:(.text+0x249): undefined reference to `sf::Window::pollEvent(sf:
:Event&)'
main.o:main.cpp:(.text+0x279): undefined reference to `sf::Color::Color(unsigned
 char, unsigned char, unsigned char, unsigned char)'
main.o:main.cpp:(.text+0x29c): undefined reference to `sf::RenderTarget::clear(s
f::Color const&)'
main.o:main.cpp:(.text+0x2b0): undefined reference to `sf::RenderStates::Default
'
main.o:main.cpp:(.text+0x2ca): undefined reference to `sf::RenderTarget::draw(sf
::Drawable const&, sf::RenderStates const&)'
main.o:main.cpp:(.text+0x2da): undefined reference to `sf::Window::display()'
main.o:main.cpp:(.text+0x2f1): undefined reference to `sf::Window::isOpen() cons
t'
main.o:main.cpp:(.text+0x331): undefined reference to `sf::RenderWindow::~Render
Window()'
main.o:main.cpp:(.text+0x38f): undefined reference to `sf::RenderWindow::~Render
Window()'
main.o:main.cpp:(.text+0x423): undefined reference to `sf::RenderWindow::~Render
Window()'
main.o:main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0xe): u
ndefined reference to `vtable for sf::CircleShape'
main.o:main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0x18):
undefined reference to `vtable for sf::CircleShape'
main.o:main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0x22):
undefined reference to `sf::Shape::~Shape()'
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [all] Error 1

Press any key to continue . . .

EDIT: I'm using Windows Mingw32 GCC compiler
« Last Edit: September 12, 2015, 05:59:55 pm by Anthony11 »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Makefile issue!?
« Reply #1 on: September 12, 2015, 06:06:21 pm »
You are not linking the libs you use.
Also remember that link order matters.

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Makefile issue!?
« Reply #2 on: September 12, 2015, 06:12:09 pm »
i thought i was!? pardon me for my ignorance, i have only written makefiles for linux until now?
what is wrong with this:
...

LIB = -Llib -lsfml-graphics-s -lfreetype -ljpeg -lsfml-window-s -lopengl32 -lgdi32 -lsfml-system-s -lwinmm

all: main.o
        g++ $(LIB) main.o -o bin\\coe.exe

...

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Makefile issue!?
« Reply #3 on: September 12, 2015, 06:34:11 pm »
i can't figure out why this doesn't work

EDIT: ok finally figured it out. apparently libs must be specified after the -o file.exe
« Last Edit: September 12, 2015, 06:38:46 pm by Anthony11 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Makefile issue!?
« Reply #4 on: September 12, 2015, 07:43:30 pm »
EDIT: ok finally figured it out. apparently libs must be specified after the -o file.exe
More like after the *.o file, because linking order matters, e.g. main.o depends on sfml-graphics, which depends on freetype, etc.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Makefile issue!?
« Reply #5 on: September 13, 2015, 07:08:10 pm »
The thing you need to remember is
... undefined reference to <FOO> ...
means "you did not link to whatever defines <FOO>" (or at least it was not visible to the linker).
Things to look for in such cases are:
- am I linking all the object files/libraries I need to?
- am I linking object files and libraries in correct order (the rules can easily be looked up online with a search engine)?
- are some of my symbols explicitly being marked as hidden (or if you've made that the default - which can make a lot of sense), have I forgotten to explicitly mark some symbols visible?