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

Author Topic: Linking problem when I try to load a font (wrong GCC version ?)  (Read 1281 times)

0 Members and 1 Guest are viewing this topic.

MrHri

  • Newbie
  • *
  • Posts: 3
    • View Profile
Linking problem when I try to load a font (wrong GCC version ?)
« on: February 01, 2018, 09:12:34 pm »
Hello,

I am new to SFML so I followed the tutorial steps to get familiar with it. Everything worked fine, until I tried to display text and got the following error:
Quote
undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'

The thing is, I am using Code::Blocks and I think the problem comes down to that. As I said, I followed very precisely the tutorial and the first issue I encountered was choosing which SFML version to download: the tutorial says "check which of the libgcc_s_sjlj-1.dll or libgcc_s_dw2-1.dll files is present in your MinGW/bin folder", but both of them are present!

I downloaded the DW2 one and got a bunch of "undefined references" so I uninstalled it and went with the SJLJ one. Once again, I configured my project exactly as the tutorial said (for dynamic libraries) and this time, the code compiled and worked fine. I thought i was done with the GCC version thing until I tried to display text and got the aforementioned error. I checked the GCC version used by CodeBlocks and it's 5.1, when the SFML SJLJ package available to download is compiled with GCC 4.9.2.

So i have 3 questions:
1) Is there a chance the error comes from something else? (knowing that the other functions work fine and I followed the tutorial instructions)
2) If not, it seems like the only reason a TDM/SJLJ version is downloadable is because Codeblocks uses this compiler. So, why not change it when Codeblocks moves to a newer version of GCC?
3) The simplest way to solve this is to compile SFML myself using cmake, right ?


Here is a simplified version of my code:
    #include <SFML/Graphics.hpp>
    #include <iostream>

    using namespace sf;

    void example(){
        // This first part worked well
        RenderWindow window(VideoMode(800, 600), "My Window");
        RectangleShape walls[10][10];

        window.clear();
        for(unsigned int i=0;i<10;i++){
            for(unsigned int j=0;j<10;j++){
                walls[j]=RectangleShape(Vector2f(8,8));
                walls[j].setPosition(16*j,16*i);
                walls[j].setFillColor(Color::White);
                window.draw(walls[j]);
            }
        }
        window.display();

        Font MyFont;
        if (!MyFont.loadFromFile("..\resources\arial.ttf")){       // The error occurs here
            std::cout<<"Error"<<std::endl;
        }
        Text text;
        text.setFont(MyFont);
    }
« Last Edit: February 01, 2018, 09:31:33 pm by MrHri »

MrHri

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Linking problem when I try to load a font (wrong GCC version ?)
« Reply #1 on: February 02, 2018, 07:34:41 pm »
Downgraded Code::Blocks to v.16 and it solved the issue. It felt wrong though :D
Seriously, could someone at least add a warning of some sort in the tutorial ? It would have saved me quite a lot of time

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Linking problem when I try to load a font (wrong GCC version ?)
« Reply #2 on: February 02, 2018, 08:54:09 pm »
You are aware that the new Code::Blocks version was released on the 30th of December? And you know, we're all developing and maintaining SFML in our free time? ;)

Plus the tutorial and the download page mention that the compiler need to match 100%.
The easiest solution is pretty much always to just rebuild SFML with your compiler, that way it matches 100% and you learn how to use CMake. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MrHri

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Linking problem when I try to load a font (wrong GCC version ?)
« Reply #3 on: February 02, 2018, 10:32:17 pm »
I was not aware of that, I just downloaded codeBlocks without paying attention because I had a new computer, sorry.
Anyway I noticed something surprising in my code (nothing to do with SFML). I actually put variables as size for my 2D array (instead of the constants of my simplified example). I used to program in C so that seemed normal to me, but apparently runtime-sized arrays are not a thing in C++. The CodeBlocks compiler (either version) doesn't seem to be aware of that, everything works and I didn't even get a warning!