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:
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);
}