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

Author Topic: "Undefined reference to sf::<insert_a_graphics_function>" errors (Linux)  (Read 4462 times)

0 Members and 1 Guest are viewing this topic.

Superpelican

  • Newbie
  • *
  • Posts: 8
    • View Profile
Hello everyone,

I'm new to C++ and SFML. Although I've read the cplusplus.com language tutorial.

I'm trying to learn SFML and I wrote a basic program. However the compiler (GCC 4.7.2 on Linux X86_64) complains with a lot of "undefined reference to" errors. I suspected that it was not my code that was causing these errors, because I've checked everything. And I was right, because trying to compile the "graphics-shape.cpp"-example (downloaded from the sfml graphics package tutorial page) results in G++ giving similiar errors. These in fact:
Code: [Select]
/tmp/ccGhjJ4e.o: In function `main':
graphics-shape.cpp:(.text+0xa1): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, std::string const&, unsigned long, sf::WindowSettings const&)'
graphics-shape.cpp:(.text+0x11e): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x13e): undefined reference to `sf::RenderTarget::Clear(sf::Color const&)'
graphics-shape.cpp:(.text+0x162): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x178): undefined reference to `sf::Color::Red'
graphics-shape.cpp:(.text+0x1a8): undefined reference to `sf::Shape::Line(float, float, float, float, float, sf::Color const&, float, sf::Color const&)'
graphics-shape.cpp:(.text+0x1c8): undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)'
graphics-shape.cpp:(.text+0x1e3): undefined reference to `sf::Color::Blue'
graphics-shape.cpp:(.text+0x1f0): undefined reference to `sf::Color::Yellow'
graphics-shape.cpp:(.text+0x210): undefined reference to `sf::Shape::Circle(float, float, float, sf::Color const&, float, sf::Color const&)'
graphics-shape.cpp:(.text+0x230): undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)'
graphics-shape.cpp:(.text+0x263): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x279): undefined reference to `sf::Color::Green'
graphics-shape.cpp:(.text+0x2a1): undefined reference to `sf::Shape::Rectangle(float, float, float, float, sf::Color const&, float, sf::Color const&)'
graphics-shape.cpp:(.text+0x2c1): undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)'
graphics-shape.cpp:(.text+0x2df): undefined reference to `sf::Shape::Shape()'
graphics-shape.cpp:(.text+0x303): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x327): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x352): undefined reference to `sf::Shape::AddPoint(float, float, sf::Color const&, sf::Color const&)'
graphics-shape.cpp:(.text+0x376): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x39a): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x3c5): undefined reference to `sf::Shape::AddPoint(float, float, sf::Color const&, sf::Color const&)'
graphics-shape.cpp:(.text+0x3e9): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x40d): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x43d): undefined reference to `sf::Shape::AddPoint(float, float, sf::Color const&, sf::Color const&)'
graphics-shape.cpp:(.text+0x45e): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x47f): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x4a4): undefined reference to `sf::Shape::AddPoint(float, float, sf::Color const&, sf::Color const&)'
graphics-shape.cpp:(.text+0x4c5): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x4e6): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x510): undefined reference to `sf::Shape::AddPoint(float, float, sf::Color const&, sf::Color const&)'
graphics-shape.cpp:(.text+0x531): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x552): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x577): undefined reference to `sf::Shape::AddPoint(float, float, sf::Color const&, sf::Color const&)'
graphics-shape.cpp:(.text+0x58e): undefined reference to `sf::Shape::SetOutlineWidth(float)'
graphics-shape.cpp:(.text+0x5a2): undefined reference to `sf::Shape::EnableFill(bool)'
graphics-shape.cpp:(.text+0x5b6): undefined reference to `sf::Shape::EnableOutline(bool)'
graphics-shape.cpp:(.text+0x5d7): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
graphics-shape.cpp:(.text+0x5ed): undefined reference to `sf::Drawable::SetColor(sf::Color const&)'
graphics-shape.cpp:(.text+0x60c): undefined reference to `sf::Drawable::Move(float, float)'
graphics-shape.cpp:(.text+0x62b): undefined reference to `sf::Drawable::Scale(float, float)'
graphics-shape.cpp:(.text+0x642): undefined reference to `sf::Drawable::Rotate(float)'
graphics-shape.cpp:(.text+0x662): undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)'
graphics-shape.cpp:(.text+0x6ab): undefined reference to `sf::RenderWindow::~RenderWindow()'
graphics-shape.cpp:(.text+0x6dd): undefined reference to `sf::RenderWindow::~RenderWindow()'
graphics-shape.cpp:(.text+0x7a4): undefined reference to `sf::RenderWindow::~RenderWindow()'
/tmp/ccGhjJ4e.o: In function `sf::Shape::~Shape()':
graphics-shape.cpp:(.text._ZN2sf5ShapeD2Ev[_ZN2sf5ShapeD5Ev]+0x14): undefined reference to `vtable for sf::Shape'
graphics-shape.cpp:(.text._ZN2sf5ShapeD2Ev[_ZN2sf5ShapeD5Ev]+0x32): undefined reference to `sf::Drawable::~Drawable()'
graphics-shape.cpp:(.text._ZN2sf5ShapeD2Ev[_ZN2sf5ShapeD5Ev]+0x5b): undefined reference to `sf::Drawable::~Drawable()'
collect2: error: ld returned 1 exit status
So either the problem is being caused by my system/setup or there's some bug in SFML 1.6 (highly unlikely, because a lot of people should've tried to compile the graphics-shape.cpp example)

Kind regards,

Superpelican
Manjaro Linux KDE 0.8.3 - GCC 4.7.2 x86_64 - KDE 4.10 - Kate Text Editor (dev environment)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: "Undefined reference to sf::<insert_a_graphics_function>" errors (Linux)
« Reply #1 on: February 19, 2013, 09:51:04 pm »
And are you linking SFML?
What is your compiling command?

Btw you should use SFML 2. ;)
(See the FAQ on the GitHub wiki for more info.)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Superpelican

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: "Undefined reference to sf::<insert_a_graphics_function>" errors (Linux)
« Reply #2 on: February 20, 2013, 09:29:52 am »
I compiled with this code: g++ -L/usr/include/sfml1.6/ -o graphics_shape_example -lsfml1.6-window -lsfml1.6-system ./graphics-shape.cpp
I used "lsfml1.6-graphics" etc. because on my system all the SFML .so' s are called libsfml1.6-graphics.so.1.6 etc. It took me days to find out that I should use "-lsfml1.6" instead of the "-lsfml" on the wiki' s  ;)

So yes I'm linking SFML.

Why I don't use SFML 2.0? Well there isn't a graphics tutorial for SFML 2 yet and some other tutorials that are available for SFML 1.6 also aren't available for SFML 2 (yet?). That' s the reason I prefer to use SFML 1.6
Manjaro Linux KDE 0.8.3 - GCC 4.7.2 x86_64 - KDE 4.10 - Kate Text Editor (dev environment)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: "Undefined reference to sf::<insert_a_graphics_function>" errors (Linux)
« Reply #3 on: February 20, 2013, 09:46:24 am »
Quote
g++ -L/usr/include/sfml1.6/ -o graphics_shape_example -lsfml1.6-window -lsfml1.6-system ./graphics-shape.cpp

I used "lsfml1.6-graphics"
Are you sure? ;)
Laurent Gomila - SFML developer

Superpelican

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: "Undefined reference to sf::<insert_a_graphics_function>" errors (Linux)
« Reply #4 on: February 20, 2013, 09:58:07 am »
Thanks alot. I've spent so much time fixing that "no such file or directory .so problem" (where I used libsfml in stead of libsfml1.6) that linking to -lsfml-window & -lsfml-system became kind of a second nature  ;)

And just use the up arrow key in my terminal emulator to get the previous command and just replaced the file names with graphics-shape.cpp, without checking if I shouldn't also edit the linking part!

The program is now happily running!
Manjaro Linux KDE 0.8.3 - GCC 4.7.2 x86_64 - KDE 4.10 - Kate Text Editor (dev environment)