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

Author Topic: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str  (Read 11352 times)

0 Members and 1 Guest are viewing this topic.

BigPaws

  • Newbie
  • *
  • Posts: 6
    • View Profile
Hi,
I'm very fresh when it comes to coding and just recently installed SFML (and the test code provided on the tutorial page worked).

Now when i tried to draw font or an image on screen im getting this error (this one's font error)

"undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'|"

My code looks like this:

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

using namespace std;

int main()
{
      sf::RenderWindow window(sf::VideoMode(800, 600, sf::Style::Default), "RPG Game");
      window.setVerticalSyncEnabled(true);

    sf::Text message;
   
    sf::Font font;
   
    font.loadFromFile("28 Days Later.ttf");

    message.setFont(font);

    message.setString("Hello world");

    message.setCharacterSize(100);

    message.setColor(sf::Color::White);

      while(window.isOpen()){

        sf::Event event;

        while(window.pollEvent(event)){
            if(event.type == sf::Event::Closed){
                window.close();
            }
        }



        window.clear(sf::Color::Black);

        //draw


        window.display();

      }


    return 0;
}
 

here is the line that gets error 
    font.loadFromFile("28 Days Later.ttf");
 

I've copied the font file to the bin folder, then to the folder where the exe is and finally to the project folder. Didnt work anyway.

I would appreciate any help i can get.

I'm using Codeblocks 16.01 (and the default compiler installed with it) and sfml 2.4.0

jamesL

  • Full Member
  • ***
  • Posts: 124
    • View Profile
I just tried it with this font
http://www.1001freefonts.com/28_days_later.font

and this SFML
http://www.sfml-dev.org/download/sfml/2.4.0/
GCC 4.9.2 TDM (SJLJ) - 32-bit

and this codeblocks
http://www.codeblocks.org/downloads/binaries
codeblocks-16.01mingw-nosetup.zip

and your code worked fine (other than a warning about setcolor being depricated)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Undefined reference is a linker error and it most of the time means that you either didn't link something properly, or that you have a library version mismatch.

Are you linking the SFML libraries in the right order?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BigPaws

  • Newbie
  • *
  • Posts: 6
    • View Profile
Created another project, installed everything again and im getting the same error, it looks like it's not even looking for the file, just prints the error.
Here are my screenshots of how i installed the sfml (tutorial from another site, since i didnt have any success with the official tutorial.








shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
You are linking only the release libraries to your overall project, rather than linking the release and debug libraries in their respective targets. I don't know if the tutorial you used mentioned this, but the reason why the official tutorials are there is because if you follow them exactly, it will work.

BigPaws

  • Newbie
  • *
  • Posts: 6
    • View Profile
Changed
""sfml-xxx-d" for Debug, and "sfml-xxx" for Release."

just like official tutorial suggested. Didn't help with this issue sadly.

jamesL

  • Full Member
  • ***
  • Posts: 124
    • View Profile
your compiler says
C:\TDM-GCC-32

where did you get that compiler ?

I'm using the one that came with codeblocks

I installed this codeblocks
codeblocks-16.01mingw-nosetup.zip
but this one should work too
codeblocks-16.01mingw-setup.exe

both come a compiler in the codeblocks\MinGW folder

so my compiler is set to the one that came with codeblocks
D:\Programs\CodeBlocks-16.01_TDM-GCC-4.9.2-32-bit-SJLJ\MinGW

http://imgur.com/a/H43Ga

(click to show/hide)

BigPaws

  • Newbie
  • *
  • Posts: 6
    • View Profile
It was installed along with exe version of this codeblocks.

When i link to my folder i get this error:

http://image.prntscr.com/image/af682c2df04e4d6884de6e4f260f370f.png

When i download nonexe version of codeblocks and just link to that folder you have i get those errors:

http://image.prntscr.com/image/072b4d13a3cb4c629c7a486b5ce9deb8.png


I'm really lost, googling doesnt help :/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Easiest solution is to get the SFML source and build SFML with whatever compiler you're using right now.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BigPaws

  • Newbie
  • *
  • Posts: 6
    • View Profile
Well, I can try that, although im not really sure if i am capable of doing it, i still suck at programming.

If noone has any other advice after work ill try yours

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Then take it as a learning experiencing. ;)

Being a programmer isn't just about hacking some code (or copy&pasting it), it's also about being able to use your toolchain in a usful way. How do I build a library? How do I build an executable? What's the difference? How does my linker work? Why do I get an undefined reference?

Also don't forget to take a look at our CMake tutorial.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BigPaws

  • Newbie
  • *
  • Posts: 6
    • View Profile
Well, I failed to building it myself, but it works just fine on Visual Studio so i guess i will stick to this IDE for now.