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

Author Topic: Undefined Reference Problem with texture.loadFromFile();  (Read 1795 times)

0 Members and 1 Guest are viewing this topic.

djninjamaster13

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Undefined Reference Problem with texture.loadFromFile();
« on: January 29, 2018, 02:06:36 pm »
Hey Guys, newbie here.

From the start, I would like to acknowledge that I know there are other posts that had this problem, but I couldn't figure out how to fix it with any of the solutions from those posts. I am using Code::Blocks 17.12 on Windows 10 with the TDM 4.9.2 (32 bit) compiler and SFML version 2.4.2. I am trying to incorporate a texture to use with a sprite, but I get an error code every time.

My code (the lines that produce the error):

sf::Texture texture;
    if (!texture.loadFromFile("")) {
        cout << "ERROR LOADING TEXTURE!!!!!" << endl;
    }

Error Code:

||=== Build: Debug in CompScience-2 (compiler: TDM Compiler17) ===|
obj\Debug\game.o||In function `main':|
C:\Users\djnin\Documents\CompScience-2\game.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|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Most posts suggested changing the compiler to match SFML, but I switched from my original GNU GCC Compiler to the TDM 4.9.2 from the SFML website and nothing changed. Should I try a different compiler or did I most likely install the TDM one incorrectly? Thanks in advance!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Undefined Reference Problem with texture.loadFromFile();
« Reply #1 on: January 29, 2018, 02:27:28 pm »
I can't remember if that was the solution, but afaik SFML wasn't built with C++11 active, so when you set it active in your project, then there might be some ABI mismatch for std::string.

The best solution is to simply rebuild SFML with whatever compiler you want to use.

While you're at it picking compilers and building SFML on your own, might I suggest taken a MinGW Builds build as they are very recent (GCC 7.2.0) and I've pretty much never ran into issues otherwise (compared to TDM builds).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/