Advertisement Jump to content
Sign in to follow this  
Taint

SFML - Can't even compile tutorial code

This topic is 1795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!