• Create Account

## SFML - Can't even compile tutorial code

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

13 replies to this topic

### #1Taint  Members

Posted 19 February 2014 - 04:53 AM

I want to learn SFML and I've tried loads of different tutorials but I just get errors with everything I put into it, whether I copy it and type it or if I paste it.

My code:

#include <SFML/Window.hpp>

int main()
{
sf::Window window;
window.create(sf::VideoMode(640,480), "Window");
while(window.isOpen())
{
sf:Event event;
while(window.pollEvent(event))
{
if(event.type = sf::Event::Closed)
window.close();
}
}
return 0;
}

Errors:

g++ -c main.cpp
main.cpp: In function ‘int main()’:
main.cpp:6:9: error: ‘class sf::Window’ has no member named ‘create’
window.create(sf::VideoMode(640,480), "Window");
^
main.cpp:7:15: error: ‘class sf::Window’ has no member named ‘isOpen’
while(window.isOpen())
^
main.cpp:9:6: error: ‘Event’ was not declared in this scope
sf:Event event;
^
main.cpp:9:6: note: suggested alternative:
In file included from /usr/include/SFML/Window.hpp:34:0,
from main.cpp:1:
/usr/include/SFML/Window/Event.hpp:197:7: note:   ‘sf::Event’
class Event
^
main.cpp:9:12: error: expected ‘;’ before ‘event’
sf:Event event;
^
main.cpp:10:16: error: ‘class sf::Window’ has no member named ‘pollEvent’
while(window.pollEvent(event))
^
main.cpp:10:26: error: ‘event’ was not declared in this scope
while(window.pollEvent(event))
^
main.cpp:13:11: error: ‘class sf::Window’ has no member named ‘close’
window.close();
^

Have I installed it wrong or am I missing something?

### #2LaboPie  Members

Posted 19 February 2014 - 05:04 AM

It seems that the compiler doesn't find the function, are you sure that you are linking the SFML libraries properly?

### #3richardurich  Members

Posted 19 February 2014 - 05:13 AM

What version of SFML headers are you using? Those look like the errors you'd get if you were using the old 1.x headers where method names started with a capital letter. If so, just download a current version of SFML (2.1?) and you should be fine.

### #4Taint  Members

Posted 19 February 2014 - 05:18 AM

Ah, turns out I was using 1.6. Thanks!

Edit: I installed 2.1 using cmake and now I'm getting this error.

g++ main.cpp -lsfml-audio -lsfml-network -lsfml-graphics -lsfml-window -lsfml-system
main.cpp:1:27: fatal error: SFML/Window.hpp: No such file or directory
#include <SFML/Window.hpp>

I really don't have the faintest idea what I'm doing, is there any reason installing this is so ridiculously difficult?

Edited by Taint, 19 February 2014 - 05:52 AM.

### #5Matt-D  Members

Posted 19 February 2014 - 06:55 AM

Try simply following the official tutorials: http://www.sfml-dev.org/tutorials/2.1/

### #6ColinDuquesnoy  Members

Posted 19 February 2014 - 07:14 AM

Did you remove SFML 1.6 before building SFML 2.0 with cmake? Did you run *make install* ? What is the output of *whereis libsfml-window*? (Assuming you're on linux)

### #7Taint  Members

Posted 19 February 2014 - 07:33 AM

Try simply following the official tutorials: http://www.sfml-dev.org/tutorials/2.1/

I did, exactly.

Did you remove SFML 1.6 before building SFML 2.0 with cmake? Did you run *make install* ? What is the output of *whereis libsfml-window*? (Assuming you're on linux)

Yeah I did, and I running "make install" seemed to do it. Now I'm getting yet another error. I can now compile my code, but can't run it.

./main
./main: error while loading shared libraries: libsfml-window.so.2: cannot open shared object file: No such file or directory

Posted 19 February 2014 - 07:41 AM

Ah, turns out I was using 1.6. Thanks!

Edit: I installed 2.1 using cmake and now I'm getting this error.

g++ main.cpp -lsfml-audio -lsfml-network -lsfml-graphics -lsfml-window -lsfml-system
main.cpp:1:27: fatal error: SFML/Window.hpp: No such file or directory
#include <SFML/Window.hpp>

I really don't have the faintest idea what I'm doing, is there any reason installing this is so ridiculously difficult?

It's telling you it doesn't know where that header file is.  You need to add a -L<include_directory> to your compile line so it knows where Window.hpp is.  You have to provide paths to all such external headers and libs.

### #9ColinDuquesnoy  Members

Posted 19 February 2014 - 08:11 AM

Yeah I did, and I running "make install" seemed to do it. Now I'm getting yet another error. I can now compile my code, but can't run it.

./main
./main: error while loading shared libraries: libsfml-window.so.2: cannot open shared object file: No such file or directory

May I ask you to open a terminal, run the following commands and paste their output here?

1) whereis libsfml-window

2) ldconfig -v 2>/dev/null | grep -v ^$'\t' Edit: the error is probably that the sfml shared object ended up in a directory that is not in your ld path. ### #10Taint Members Posted 19 February 2014 - 09:29 AM tom@tom-M52LT-D3 ~$ whereis libsfml-window
libsfml-window: /usr/local/lib/libsfml-window.so
tom@tom-M52LT-D3 ~ $ldconfig -v 2>/dev/null | grep -v ^$'\t'
/usr/lib/i386-linux-gnu/mesa:
/lib/i386-linux-gnu:
/usr/lib/i386-linux-gnu:
/usr/local/lib:
/usr/lib/nvidia-settings-319:
/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu/mesa-egl:
/usr/lib/x86_64-linux-gnu/mesa:
/lib:
/usr/lib:

### #11dejaime  Members

Posted 19 February 2014 - 10:56 AM

You probably need to include the SFML directory.
Something like this:

g++ -c main.cpp -I~SFML_INCLUDE_DIRECTORY_GOES_HERE~
//like in
g++ -c main.cpp -I/home/me/SFML/include

I'd personally use an IDE.

@edit

Yeah I did, and I running "make install" seemed to do it. Now I'm getting yet another error. I can now compile my code, but can't run it.

./main
./main: error while loading shared libraries: libsfml-window.so.2: cannot open shared object file: No such file or directory

If g++ is building your program successfully, but you can't find it, look if the main executable wasn't generated in a different directory. Using -o to specify a name, as in g++ main.cpp -o program.exe can help you locate it.

But this may be a linkage problem; linking statically will probably solve this.

Edited by dejaime, 19 February 2014 - 11:55 AM.

### #12richardurich  Members

Posted 19 February 2014 - 12:08 PM

The only other thing I can think of is maybe you would be missing the symbolic link from .so.2 to .so.2.1 somehow.

Edit: removed bit about ldconfig since you weren't grepping the file, so that shouldn't be the problem.

Edited by richardurich, 19 February 2014 - 12:11 PM.

### #13BeerNutts  Members

Posted 19 February 2014 - 10:37 PM

Ah, turns out I was using 1.6. Thanks!

Edit: I installed 2.1 using cmake and now I'm getting this error.

g++ main.cpp -lsfml-audio -lsfml-network -lsfml-graphics -lsfml-window -lsfml-system
main.cpp:1:27: fatal error: SFML/Window.hpp: No such file or directory
#include <SFML/Window.hpp>

I really don't have the faintest idea what I'm doing, is there any reason installing this is so ridiculously difficult?

It's telling you it doesn't know where that header file is.  You need to add a -L<include_directory> to your compile line so it knows where Window.hpp is.  You have to provide paths to all such external headers and libs.

Not -L, -I (capital i).

-L is for specifying library paths.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

### #14dejaime  Members

Posted 20 February 2014 - 10:06 AM

./main: error while loading shared libraries: libsfml-window.so.2: cannot open shared object file: No such file or directory

Not -L, -I (capital i).

-L is for specifying library paths.

He has already fixed the include path problem. It looks like he just didn't copy the necessary files for the shared linking.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.