SFML community forums

Help => Graphics => Topic started by: buster on September 26, 2016, 11:03:36 pm

Title: LoadFromFile undefined reference problem
Post by: buster on September 26, 2016, 11:03:36 pm
I have no idea what to do. I tried loading images (bmp), music (wav) or font (ttf) with LoadFromFile function, but the compiler always spits out similar error.

|In function `main':|
C:\_stuff\code blocks\projects\game1\main.cpp|14|undefined reference to `sf::Texture::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)'|
C:\_stuff\code blocks\projects\game1\main.cpp|15|undefined reference to `sf::Font::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
 

This is how the source code looks:

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

int main()
{
    sf::Font font;
    sf::Texture hero_idle_texture;
    hero_idle_texture.loadFromFile("hero_idle.bmp");
    font.loadFromFile("arial.ttf");
    return 0;
}

I put files both in the obj file and in the exe file directory. I tried reinstalling SFML, compiler and Code::Blocks several times, but it didn't work.

I'm programming in Code::Blocks, using SFML 2.3.2 and my OS is Windows 10 64 bit.

I also tried to recompile SFML using CMake but I got this problem: http://stackoverflow.com/questions/39680283/cannot-generate-files-with-cmake-using-mingw-makefiles
Title: AW: LoadFromFile undefined reference problem
Post by: eXpl0it3r on September 27, 2016, 02:05:51 am
Your SFML binaries probably weren't built with the same compiler as you're trying to use for compiling your app.
For SFML 2.3.2 we didn't provide binaries for the latest compiler version that currently ship with Code::Blocks.

Your options are: Use a compiler linked on the download page.
Or build SFML with your current compiler.

Also consider upgrading to SFML 2.4. ;)
Title: Re: LoadFromFile undefined reference problem
Post by: jamesL on September 27, 2016, 06:21:59 pm
yeah, if you're using this one
codeblocks-16.01mingw-setup.exe
"The codeblocks-16.01mingw-setup.exe file includes additionally the GCC/G++ compiler and GDB debugger from TDM-GCC (version 4.9.2, 32 bit, SJLJ)."
from
http://www.codeblocks.org/downloads/binaries

then you want
GCC 4.9.2 TDM (SJLJ) - 32-bit
from
http://www.sfml-dev.org/download/sfml/2.4.0/
Title: Re: LoadFromFile undefined reference problem
Post by: buster on September 27, 2016, 07:21:05 pm
Thank you a plenty eXpl0it3r, this fixed my issue.