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

Author Topic: How to compile and run a game made with SFML?  (Read 5773 times)

0 Members and 1 Guest are viewing this topic.

louie

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
How to compile and run a game made with SFML?
« on: August 23, 2015, 04:31:31 pm »
Hi, so I created a very simple game with SFML and I wanna try it out, so how can I compile an SFML game and run it ? By the way, I'm using MinGW g++ compiler, is that good enough? or do I need a couple more things?

Thanks in advance :)

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: How to compile and run a game made with SFML?
« Reply #1 on: August 23, 2015, 04:33:58 pm »
Are you using CodeBlocks, or are you using the compiler via the command line? I'd recommend following this: http://www.sfml-dev.org/tutorials/2.3/start-cb.php

louie

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: How to compile and run a game made with SFML?
« Reply #2 on: August 23, 2015, 05:24:36 pm »
Well, I don't have CodeBlocks, do I need to install it? or I can just compile my SFML game from the command line with g++ ?

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: How to compile and run a game made with SFML?
« Reply #3 on: August 23, 2015, 05:38:45 pm »
You can compile it through the command line, but the point of an IDE is that once configured, it lets you compile/run with a single click rather than a long command that includes linking.

louie

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: How to compile and run a game made with SFML?
« Reply #4 on: August 24, 2015, 11:29:24 am »
Ok I'll try CodeBlocks. :)

Edit: Ok, so I tried to follow that link( http://www.sfml-dev.org/tutorials/2.3/start-cb.php), I tried that example there, made a main.cpp file but when I went to Build > Compile current file, I got alot of errors.
main.o:main.cpp|| undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf5Color5GreenE'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf6Window5closeEv'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf6Window7displayEv'|
main.o:main.cpp|| undefined reference to `_imp___ZNK2sf6Window6isOpenEv'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
main.o:main.cpp|| undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
||=== Build failed: 17 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
 
Help please? :(
« Last Edit: August 24, 2015, 12:22:08 pm by louie »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to compile and run a game made with SFML?
« Reply #5 on: August 24, 2015, 01:23:04 pm »
Please read the tutorial more carefully and make sure you follow every single step: linking the right libraries with the right suffixes, defining SFML_STATIC or not, etc...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

louie

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: How to compile and run a game made with SFML?
« Reply #6 on: August 25, 2015, 06:41:37 am »
Ok I re-read the tutorial, added the dependencies in the project, but I got a new error:
||=== Build: Debug in Test (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Games\SFML Games\Test\main.cpp|5|undefined reference to `sf::String::String(char const*, std::locale const&)'|
C:\Games\SFML Games\Test\main.cpp|5|undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'|
C:\Games\SFML Games\Test\main.cpp|5|undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'|
C:\Games\SFML Games\Test\main.cpp|6|undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'|
C:\Games\SFML Games\Test\main.cpp|7|undefined reference to `sf::Color::Green'|
C:\Games\SFML Games\Test\main.cpp|7|undefined reference to `sf::Shape::setFillColor(sf::Color const&)'|
C:\Games\SFML Games\Test\main.cpp|15|undefined reference to `sf::Window::close()'|
C:\Games\SFML Games\Test\main.cpp|12|undefined reference to `sf::Window::pollEvent(sf::Event&)'|
C:\Games\SFML Games\Test\main.cpp|18|undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'|
C:\Games\SFML Games\Test\main.cpp|18|undefined reference to `sf::RenderTarget::clear(sf::Color const&)'|
C:\Games\SFML Games\Test\main.cpp|19|undefined reference to `sf::RenderStates::Default'|
C:\Games\SFML Games\Test\main.cpp|19|undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'|
C:\Games\SFML Games\Test\main.cpp|20|undefined reference to `sf::Window::display()'|
C:\Games\SFML Games\Test\main.cpp|9|undefined reference to `sf::Window::isOpen() const'|
C:\Games\SFML Games\Test\main.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\Games\SFML Games\Test\main.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\Games\SFML Games\Test\main.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
obj\Debug\main.o||In function `ZN2sf11CircleShapeD1Ev':|
C:\Program Files\SFML-2.3.1\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `vtable for sf::CircleShape'|
C:\Program Files\SFML-2.3.1\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `vtable for sf::CircleShape'|
C:\Program Files\SFML-2.3.1\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `sf::Shape::~Shape()'|
||=== Build failed: 20 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
 
I don't how to fix that D:

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: How to compile and run a game made with SFML?
« Reply #7 on: August 25, 2015, 06:53:32 am »
Are you trying to compile a 32 bit executable with a 64 bit version of SFML?
http://www.sfml-dev.org/faq.php#tr-grl-64bit

louie

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: How to compile and run a game made with SFML?
« Reply #8 on: August 25, 2015, 07:06:14 am »
Nope, I have the 32-bit version of SFML.

louie

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: How to compile and run a game made with SFML?
« Reply #9 on: August 25, 2015, 11:01:19 am »
Ok, so I followed this in youtube and I almost done it, but there is 1 error left that is annoying me.
||=== Build: Debug in Test (compiler: GNU GCC Compiler) ===|
C:\Program Files\SFML-2.3.1\lib\libsfml-system-s-d.a(String.cpp.obj)||In function `ZNKSbIjSt11char_traitsIjESaIjEE8_M_checkEjPKc':|
C:\Dev\MinGW32-PosixDwarf492r2\i686-w64-mingw32\include\c++\bits\basic_string.h|324|undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
 
How can I fix that?
Edit: Uh, bump. I still can't fix that problem. Help please.
« Last Edit: August 26, 2015, 10:52:53 am by louie »

jamesL

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: How to compile and run a game made with SFML?
« Reply #10 on: August 26, 2015, 06:25:22 pm »
my opinion, don't use static linking -- it just makes things easier not to

from
http://www.sfml-dev.org/tutorials/2.3/start-cb.php
"Static SFML libraries have the "-s" suffix: "sfml-xxx-s-d" for Debug, and "sfml-xxx-s" for Release."

so instead of
libsfml-system-s-d.a
use
libsfml-system-d.a
this will mean copying the dlls into your system32 folder or into the same folder as your .exe, but that's fine

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: How to compile and run a game made with SFML?
« Reply #11 on: August 26, 2015, 06:31:18 pm »
On the other hand, I would say it is much easier to do a slightly longer suffix than make sure you have the exact correct version of the exact correct files in the exact correct folder for each project that you do.

 

anything