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

Author Topic: [Solved]Problem loading font SFML 2  (Read 3183 times)

0 Members and 1 Guest are viewing this topic.

PhrayShow

  • Newbie
  • *
  • Posts: 2
    • View Profile
[Solved]Problem loading font SFML 2
« on: July 27, 2015, 04:20:58 am »
Hi, I am new to C++ and have recently started to study SFML too. After I've followed all the steps in order to create a dynamically linked SFML project on Code::Blocks, I was able to make some basic coding such as creating a window, printing shapes, using user imput to move shapes, etc. but when I  tried to put some text on the screen I got the error message:

"C:\CPP\IntroductionSFML\main.cpp|10|undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE|".

The line to which it reffers is this:

font.loadFromFile("arial.ttf");

Here is the code I'm trying to compile (I reduced it to the minimum, but at first I was trying to use text in a bigger code):

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


int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Application");

sf::Font font;
font.loadFromFile("arial.ttf");


sf::Text text("Hello!", font, 30);
text.setPosition(50,50);
text.setColor(sf::Color::Green);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(text);
window.display();
}
}

I think this problem is not related to the directory where I've put the font file, because when I tried to run the following code, I've got the exactly same message.

if (!font.loadFromFile("arial.ttf"))
{
    // error...
}
 



As I said before, SFML worked perfectly well when I was using other resources, such as shapes, window, events, keyboard, etc.

Please, could you help me finding out what is the problem?

« Last Edit: July 28, 2015, 02:45:23 am by PhrayShow »

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: Problem loading font SFML 2
« Reply #1 on: July 27, 2015, 09:27:42 am »
Quote
As I said before, SFML worked perfectly well when I was using other resources, such as shapes, window, events, keyboard, etc. 

Happened to me once, but my problem was the sf::Image and its because i was using different version of headers and libs of SFML.
http://en.sfml-dev.org/forums/index.php?topic=18238.msg131273#msg131273
« Last Edit: July 27, 2015, 09:32:29 am by lorence30 »

PhrayShow

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Problem loading font SFML 2
« Reply #2 on: July 28, 2015, 02:44:42 am »
Hi lorence, thanks for the reply. My problem was in fact similar to yours. I think I have download SFML 2.3.1 for gcc 4.8.1 compiler when I was actually using gcc 4.7.1 After downloading the right SFML package it worked well.

Thanks!