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

Author Topic: LoadFromFile undefined reference problem  (Read 6074 times)

0 Members and 1 Guest are viewing this topic.

buster

  • Newbie
  • *
  • Posts: 5
    • View Profile
LoadFromFile undefined reference problem
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11047
    • View Profile
    • development blog
    • Email
AW: LoadFromFile undefined reference problem
« Reply #1 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. ;)
« Last Edit: September 27, 2016, 07:26:26 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jamesL

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: LoadFromFile undefined reference problem
« Reply #2 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/

buster

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: LoadFromFile undefined reference problem
« Reply #3 on: September 27, 2016, 07:21:05 pm »
Thank you a plenty eXpl0it3r, this fixed my issue.