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

Author Topic: cant run SFML on Code::Blocks  (Read 7780 times)

0 Members and 1 Guest are viewing this topic.

zys5945

  • Newbie
  • *
  • Posts: 16
    • View Profile
cant run SFML on Code::Blocks
« on: March 09, 2015, 07:52:42 pm »
Just followed the tutorial and tried to compile the example code but got error messages:

||=== Build: Debug in test (compiler: GNU GCC Compiler) ===|
obj\Debug\src\test.o||In function `main':|
C:\test\src\test.cpp|5|undefined reference to `sf::String::String(char const*, std::locale const&)'|
C:\test\src\test.cpp|5|undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'|
C:\test\src\test.cpp|5|undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'|
C:\test\src\test.cpp|6|undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'|
C:\test\src\test.cpp|7|undefined reference to `sf::Color::Green'|
C:\test\src\test.cpp|7|undefined reference to `sf::Shape::setFillColor(sf::Color const&)'|
C:\test\src\test.cpp|15|undefined reference to `sf::Window::close()'|
C:\test\src\test.cpp|12|undefined reference to `sf::Window::pollEvent(sf::Event&)'|
C:\test\src\test.cpp|18|undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'|
C:\test\src\test.cpp|18|undefined reference to `sf::RenderTarget::clear(sf::Color const&)'|
C:\test\src\test.cpp|19|undefined reference to `sf::RenderStates::Default'|
C:\test\src\test.cpp|19|undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'|
C:\test\src\test.cpp|20|undefined reference to `sf::Window::display()'|
C:\test\src\test.cpp|9|undefined reference to `sf::Window::isOpen() const'|
C:\test\src\test.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\test\src\test.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
C:\test\src\test.cpp|23|undefined reference to `sf::RenderWindow::~RenderWindow()'|
obj\Debug\src\test.o||In function `ZN2sf11CircleShapeD1Ev':|
C:\SFML-2.2\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `vtable for sf::CircleShape'|
C:\SFML-2.2\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `vtable for sf::CircleShape'|
C:\SFML-2.2\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)) ===|

seems like a linker problem but i did link sfml-graphics sfml-window and sfml-system, cant figure out what's wrong, any help?

zys5945

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #1 on: March 09, 2015, 07:58:41 pm »
tried to link other dependencies but got same error

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: cant run SFML on Code::Blocks
« Reply #2 on: March 09, 2015, 09:24:34 pm »
What's the command you're using to compile?

If I remember the naming scheme for Windows correctly, I think the libraries all have a "-2" on the end of the lib name.

So, for ex:
sfml-window-2

zys5945

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #3 on: March 10, 2015, 12:04:48 am »
thx for the reply, i used Code::Blocks to compile and the command is
mingw32-g++.exe -Wall -DSFML_STATIC -g -IC:\SFML-2.2\include -Iinclude -c C:\test\src\test.cpp -o obj\Debug\src\test.o
i think all the linkers are working fine else i will get error message on that

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #4 on: March 10, 2015, 12:07:46 am »
You're not linking sfml-graphics etc.
Moreover if you're statically linking you also need to link SFML dependencies.

If you're sure that you linked them, maybe you linked them in release mode but not in debug.

zys5945

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #5 on: March 10, 2015, 12:47:23 am »
under link libraries i got sfml-graphics sfml-window and sfml-system in that order, as u can see i got dynamic links and i included my linker and compiler with SFML\lib and SFML\include, i tried static linking with command
mingw32-g++.exe -LC:\SFML-2.2\lib -o bin\Debug\test.exe obj\Debug\src\test.o   -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lwinmm -lgdi32 -lglew32 -ljpeg -lfreetype -lopengl32
but same thing happened

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: cant run SFML on Code::Blocks
« Reply #6 on: March 10, 2015, 01:29:42 am »
What are the filenames of the libraries in C:\SFML-2.2\lib?

zys5945

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #7 on: March 10, 2015, 02:56:43 am »
libfreetype.a
libglew.a
libjpeg.a
libopenal32.a
libsfml-audio.a
etc

it is the gcc 4.8.1 x64 version of sfml 2.2, i got the correct gcc version and 64bit os

zys5945

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #8 on: March 10, 2015, 03:00:56 am »
the ide itself even give me autocomplete, if i type "sf::R" renderwindow will show up

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: cant run SFML on Code::Blocks
« Reply #9 on: March 10, 2015, 03:12:04 am »
Looks like you need to get rid of the "-s" on all the libraries for the linker command.

Notice the sfml libraries filenames don't have it.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: cant run SFML on Code::Blocks
« Reply #10 on: March 10, 2015, 10:04:16 am »
You need to decide whether you want to link statically or dynamically.

If you choose static:
Make sure SFML_STATIC is defined.
Make sure to link against the libraries with the -s suffix and check that these files actually exist.
Make sure to link against SFML's dependencies.
Make sure the link order is correct.

If you choose dynamic:
Make sure SFML_STATIC is not defined.
Make sure to link against the libraries without the -s suffix and check that these files actually exist.
Make sure the link order is correct.

For both cases you'll need to make sure to not mix debug and release modes. In debug mode link against the libraries with the -d suffix. In release mode link against the libraries without the -d suffix.

And as usually everything is explained in the official tutorial, you just need to follow it step by step without skipping bits here and there. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

zys5945

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #11 on: March 10, 2015, 11:38:10 pm »
Thank you for the help

I did read through the tutorial but still can't get it working, i tried static and dynamic linking with release mode, the files are there, but when I use dynamic linking and delete the SFML_STATIC define, i got some different error messages:

||=== Build: Debug in test (compiler: GNU GCC Compiler) ===|
obj\Debug\src\test.o||In function `main':|
C:\test\src\test.cpp|5|undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'|
C:\test\src\test.cpp|5|undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'|
C:\test\src\test.cpp|5|undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'|
C:\test\src\test.cpp|6|undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'|
C:\test\src\test.cpp|7|undefined reference to `_imp___ZN2sf5Color5GreenE'|
C:\test\src\test.cpp|7|undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'|
C:\test\src\test.cpp|15|undefined reference to `_imp___ZN2sf6Window5closeEv'|
C:\test\src\test.cpp|12|undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'|
C:\test\src\test.cpp|18|undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'|
C:\test\src\test.cpp|18|undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'|
C:\test\src\test.cpp|19|undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'|
C:\test\src\test.cpp|19|undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'|
C:\test\src\test.cpp|20|undefined reference to `_imp___ZN2sf6Window7displayEv'|
C:\test\src\test.cpp|9|undefined reference to `_imp___ZNK2sf6Window6isOpenEv'|
C:\test\src\test.cpp|23|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
C:\test\src\test.cpp|23|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
C:\test\src\test.cpp|23|undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'|
obj\Debug\src\test.o||In function `ZN2sf11CircleShapeD1Ev':|
C:\test\..\SFML-2.2\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZTVN2sf11CircleShapeE'|
C:\test\..\SFML-2.2\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZTVN2sf11CircleShapeE'|
C:\test\..\SFML-2.2\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZN2sf5ShapeD2Ev'|
||=== Build failed: 20 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #12 on: March 10, 2015, 11:56:21 pm »
You should always post the command line used to build your project (http://en.sfml-dev.org/forums/index.php?topic=12552.0) with your errors, it grealtly helps to spot what you did wrong.
Are you sure you removed the -s in the linker?

zys5945

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: cant run SFML on Code::Blocks
« Reply #13 on: March 11, 2015, 12:20:58 am »
command line was like this :

mingw32-g++.exe -L..\SFML-2.2\lib -o bin\Debug\test.exe obj\Debug\src\test.o   -lsfml-graphics -lsfml-window -lsfml-system

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: cant run SFML on Code::Blocks
« Reply #14 on: March 11, 2015, 12:36:53 am »
Official FAQ

Last paragraph...
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything