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

Author Topic: SFML - Error creating a texture  (Read 1730 times)

0 Members and 1 Guest are viewing this topic.

skoda

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML - Error creating a texture
« on: June 28, 2017, 11:26:03 am »
Hi. I want to create a basic texture in SFML, Code::Blocks, but I am still receiving an extremly annoying and weird error:
Quote
C:\Users\user\Desktop\Wow\main.cpp|10|undefined reference to `sf::Texture::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)'|
||error: ld returned 1 exit status|.

I looked for a reliable code from a tutorial, but this error still keeps occuring.
This is the code:

#include "SFML/Graphics.hpp"
#include <iostream>

int main()
{
        sf::RenderWindow window( sf::VideoMode( 600, 600 ), "SFML WORK!" );

        sf::Texture texture;

        if (!texture.loadFromFile("simplypears.jpg"))
        {
                std::cout << "Error loading paddle texture :(" << std::endl;
        }

        //sf::Sprite sprite(texture);

        // or

        sf::Sprite sprite;
        sprite.setTexture(texture);

        while ( window.isOpen( ) )
        {
                sf::Event event;

                while ( window.pollEvent( event ) )
                {
                        switch (event.type)
                        {
                        case sf::Event::Closed:
                                window.close();

                                break;

                        }
                }

                window.clear( );

                window.draw(sprite);

                window.display( );
        }
}
I really want to learn SFML and create cool things, but this exasperating error stops me.
So please help me!
« Last Edit: June 28, 2017, 11:39:56 am by Laurent »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10827
    • View Profile
    • development blog
    • Email
Re: SFML - Error creating a texture
« Reply #1 on: June 28, 2017, 11:48:38 am »
Easiest solution would be to rebuild SFML. The issue is that the string class used with SFML and the one used in your own code have different implementations and are not compatible.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

skoda

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML - Error creating a texture
« Reply #2 on: June 28, 2017, 12:06:32 pm »
Thanks, but how to rebuild SFML? :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10827
    • View Profile
    • development blog
    • Email
Re: SFML - Error creating a texture
« Reply #3 on: June 28, 2017, 12:08:04 pm »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

skoda

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML - Error creating a texture
« Reply #4 on: June 28, 2017, 12:09:27 pm »
Maybe the problem is with the compiler? I use GNU GCC Compiler

 

anything