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

Author Topic: Undefined refference to sf::Texture::loadFromFile  (Read 2312 times)

0 Members and 1 Guest are viewing this topic.

Negawisp

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Undefined refference to sf::Texture::loadFromFile
« on: April 06, 2018, 12:00:13 pm »
Having compiled a small program using g++-4.8
g++-4.8 -c main.cpp
and trying to link it with SFML files, using g++-4.8 as well,
g++-4.8 -o main.o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
I've encountered such problem:
main.cpp:(.text+0x234): undefined reference to `sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)'

I've already checked another topic, and the key to the problem was rebuilding SFML so that the IDE and the up-to-date compiler could use it properly. But I feel like that might not work in my case, as I do not use IDE. What are the other possible precursors to this problem?
« Last Edit: April 06, 2018, 12:25:49 pm by Negawisp »

Negawisp

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Undefined refference to sf::Texture::loadFromFile
« Reply #1 on: April 06, 2018, 12:27:52 pm »
The code itself:
#define SFML_STATIC

#include <SFML/Graphics.hpp>
//#include <SFML/Audio.hpp>

#define WASSERT() printf ("Error in file %s, functon %s, on line %d.", \
                          __FILE__, __PRETTY_FUNCTION__, __LINE__);


int main ()
{
        sf::RenderWindow window (sf::VideoMode (200, 200), "Hello!");
        system ("say 2");

        //sf::IntRect rectangle (0, 0, 200, 200);
        sf::Rect<int> rectangle1 (0, 0, 200, 200);

        sf::Texture hello_texture;
        hello_texture.loadFromFile ("hello-world.jpg", rectangle1) || WASSERT ();

        sf::Sprite hello_sprite;
        hello_sprite.setTexture (hello_texture);

        //sf::CircleShape shape (100.f);
        //shape.setFillColor (sf::Color::Green);

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent (event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                if (sf::Keyboard::isKeyPressed (sf::Keyboard::Escape))
                        break;

                window.clear ();
                window.draw (hello_sprite);
                //window.draw (shape);
                window.display ();
        }

        return 0;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Undefined refference to sf::Texture::loadFromFile
« Reply #2 on: April 06, 2018, 12:29:03 pm »
It's never about the IDE, it's always about the compiler the IDE uses.

So where did you get SFML from? What OS are you using?
If that version wasn't built with the exact same compiler that you use, it might not work.

You shouldn't define SFML_STATIC in your code and you shouldn't define SFML_STATIC at all if you're not linking SFML statically.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Negawisp

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Undefined refference to sf::Texture::loadFromFile
« Reply #3 on: April 06, 2018, 07:17:07 pm »
It's never about the IDE, it's always about the compiler the IDE uses.

So where did you get SFML from? What OS are you using?
If that version wasn't built with the exact same compiler that you use, it might not work.

You shouldn't define SFML_STATIC in your code and you shouldn't define SFML_STATIC at all if you're not linking SFML statically.

I got it with sudo apt-get install libsfml-dev. I am using lubuntu. I got your point with SFML_STATIC, thank you.
While waiting for response I will now try to build new version with up-to-date tools :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Undefined refference to sf::Texture::loadFromFile
« Reply #4 on: April 06, 2018, 07:34:11 pm »
Most if not all libraries and applications in the package manager will be built with the standard GCC version that is in the package manager, when you explicitly pick a different compiler version, things might just not be compatible.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything