SFML error?

Heres the code, I'm following the getting started tut on the sfml site
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <SFML/System.hpp>
#include <iostream>
using namespace std;
using namespace sf;
int main()
{
    sf::Clock Clock;
    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }

    return 0;
}

and the error is

obj\Debug\main.o||In function `main':|
C:\Program Files\CodeBlocks\SFML training\main.cpp|7|undefined reference to `_imp___ZN2sf5ClockC1Ev'|
C:\Program Files\CodeBlocks\SFML training\main.cpp|10|undefined reference to `_imp___ZNK2sf5Clock14GetElapsedTimeEv'|
C:\Program Files\CodeBlocks\SFML training\main.cpp|11|undefined reference to `_imp___ZN2sf5SleepEj'|
C:\Program Files\CodeBlocks\SFML training\main.cpp|8|undefined reference to `_imp___ZNK2sf5Clock14GetElapsedTimeEv'|
||=== Build finished: 4 errors, 0 warnings ===|
What is the problem? I followed the tutorial exactly
I followed the tutorial exactly


You missed a step. You need to link to the libraries. (in this case, sfmlsystem).

http://www.sfml-dev.org/tutorials/1.6/start-cb.php

Search the page for this:

Open your project's build options, then go to the Linker settings tab. In Other link options, add the SFML libraries you are using, with the "-l" directive.


That paragraph and the picture below it shows you what you need to do.
Oh. That's dumb. You'd think it would tell you to start coding AFTER they had you set it up. now I'm getting the error:
C:\Program Files\CodeBlocks\SFML training\main.cpp|11|undefined reference to `_imp___ZN2sf5SleepEj'|.
Just that one, all the others are gone.
Hmm. I would have thought Sleep would be in the system lib as well.

Try also linking to the sfml-window lib.
Nothing changed.
And....no response
Last edited on
Well the issue is definitely that you need to link to the right lib. I just don't know which one that is (the docs don't seem to say either).

If system and window don't work, then maybe try graphics? Try all of them until you figure it out.

Also I'm not on these boards every minute, so don't expect a response so fast =P
No matter what I link to it doesn't work! This sucks!
Note that you also have to link to the correct libs in order. Window depends on system and graphics depends on Window.
Last edited on
I wouldn't think that would matter, but I guess it's worth a shot.
I linked to them both in different orders, no change.
Can you take a screenshot or copy/paste exactly how you're linking?
How do I put in pictures? Should I just upload it to photobucket or something and paste a link?
Yeah
OH! Does it make a difference that I'm using SFML 2.0?
Yes it does. There is a tutorial for setting up SFML 2.0.
It says nothing about codeblocks though, and something about cmake. I don't know what cmake is
For SFML 2.0 you have to go get CMake and compile the libs yourself. Then move them to wherever and link them like normal.
That's....really dumb. But okay. Is cmake just something that makes it so the libs work?
Cmake basically makes something that makes the libs for you. Like a makefile for GCC/others or a Visual Studio project. You basically just run that and you'll get the libs out of it.
Topic archived. No new replies allowed.