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

Author Topic: Can't load image (C++, CodeBlocks)  (Read 3181 times)

0 Members and 1 Guest are viewing this topic.

xLuka

  • Newbie
  • *
  • Posts: 4
    • View Profile
Can't load image (C++, CodeBlocks)
« on: April 22, 2019, 12:20:58 am »
Hey, can anyone help me about this?

My code:
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
 sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML Test Program", sf::Style::Close | sf::Style::Resize);
 sf::RectangleShape player(sf::Vector2f(100.0f,100.0f));
player.setPosition(206.0f, 206.0f);
sf::Texture playerTexture;
playerTexture.loadFromFile("dino.jpg");
player.setTexture(&playerTexture);





 while(window.isOpen()) {
     sf::Event evnt;
     while(window.pollEvent(evnt)){

        switch (evnt.type)
        {
           case sf::Event::Closed:
            window.close();
           break;

     window.clear();
     window.draw(player);
     window.display();
 }
    return 0;
}}}


The error I get every time:
||=== Build: Debug in sfmlprogram (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Users\DJuca\Desktop\Programiranje Cpp\sfmlprogram\main.cpp|10|undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

- So if anyone know what is it all about please answer me :P thank you

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't load image (C++, CodeBlocks)
« Reply #1 on: April 22, 2019, 01:39:14 am »
Although I can't explain your error, I would like to just point out something important in your code: your clear/draw/display (and return) should not be within the event type switch or even the event loop. To fix, place 2 closing braces before window.clear() and remove 2 closing braces from the end of the code.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

OceanJeff40

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Can't load image (C++, CodeBlocks)
« Reply #2 on: April 22, 2019, 01:56:33 am »
Do you need to include texture.hpp?
#include <Texture.hpp>

Regards,

Jeff Cummings

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Can't load image (C++, CodeBlocks)
« Reply #3 on: April 22, 2019, 09:44:56 am »
If you have activated C++11 support, then you'll probably have to rebuild SFML with the same compiler flags, otherwise the runtimes are in conflict.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

xLuka

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Can't load image (C++, CodeBlocks)
« Reply #4 on: April 22, 2019, 12:26:28 pm »
Although I can't explain your error, I would like to just point out something important in your code: your clear/draw/display (and return) should not be within the event type switch or even the event loop. To fix, place 2 closing braces before window.clear() and remove 2 closing braces from the end of the code.

Thank you for that :D

xLuka

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Can't load image (C++, CodeBlocks)
« Reply #5 on: April 22, 2019, 12:27:27 pm »
Do you need to include texture.hpp?
#include <Texture.hpp>

Regards,

Jeff Cummings

I tried, but it says : fatal error : <Texture.hpp> no such file or directory ;(

xLuka

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Can't load image (C++, CodeBlocks)
« Reply #6 on: April 22, 2019, 12:30:53 pm »
If you have activated C++11 support, then you'll probably have to rebuild SFML with the same compiler flags, otherwise the runtimes are in conflict.

No, I have C++14

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't load image (C++, CodeBlocks)
« Reply #7 on: April 22, 2019, 10:39:42 pm »
Just to clarify with the suggestion about including Texture.hpp, to include it, you'd need SFML before it:
#include <SFML/Texture.hpp>

However, Texture is automatically included by the Graphics module.

Again, not fixing your issue, sorry; just clarifying some points.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

OceanJeff40

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Can't load image (C++, CodeBlocks)
« Reply #8 on: April 23, 2019, 02:42:34 am »
Have you compiled any demos or programs at all yet with SFML?  You might be missing a .lib in the LINKER INPUT settings for the solution/project.

Right click on your project in Visual Studio, all the way down to properties, open Linker tab, then highlight INPUT settings, and they should be listed under 'Additional Dependencies'.  (You may already be familiar with this, and you may already have it setup correctly, just double checking.)  8)

For now, that's all I have,

Jeff

OceanJeff40

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Can't load image (C++, CodeBlocks)
« Reply #9 on: April 23, 2019, 02:43:27 am »
and on mine it's actually SFML/Graphics/Texture.hpp

I was just looking at the texture demo in the SFML demo files.

Jeff

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Can't load image (C++, CodeBlocks)
« Reply #10 on: April 23, 2019, 08:10:28 am »
No, I have C++14

Then you have to rebuild SFML with that flag set active.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything