SFML error?

Aug 30, 2011 at 4:55am
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
Aug 30, 2011 at 4:58am
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.
Aug 30, 2011 at 5:02am
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.
Aug 30, 2011 at 5:08am
Hmm. I would have thought Sleep would be in the system lib as well.

Try also linking to the sfml-window lib.
Aug 30, 2011 at 5:11am
Nothing changed.
And....no response
Last edited on Aug 30, 2011 at 5:55am
Aug 30, 2011 at 6:37am
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
Aug 30, 2011 at 7:21am
No matter what I link to it doesn't work! This sucks!
Aug 30, 2011 at 10:56am
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 Aug 30, 2011 at 10:56am
Aug 30, 2011 at 1:52pm
I wouldn't think that would matter, but I guess it's worth a shot.
Aug 30, 2011 at 5:18pm
I linked to them both in different orders, no change.
Aug 30, 2011 at 5:48pm
Can you take a screenshot or copy/paste exactly how you're linking?
Aug 30, 2011 at 6:36pm
How do I put in pictures? Should I just upload it to photobucket or something and paste a link?
Aug 30, 2011 at 6:39pm
Yeah
Aug 30, 2011 at 6:51pm
Aug 30, 2011 at 9:14pm
OH! Does it make a difference that I'm using SFML 2.0?
Aug 30, 2011 at 10:00pm
Yes it does. There is a tutorial for setting up SFML 2.0.
Aug 30, 2011 at 10:07pm
It says nothing about codeblocks though, and something about cmake. I don't know what cmake is
Aug 30, 2011 at 10:34pm
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.
Aug 30, 2011 at 10:35pm
That's....really dumb. But okay. Is cmake just something that makes it so the libs work?
Aug 30, 2011 at 10:38pm
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.