SFML community forums

Help => Graphics => Topic started by: BigPaws on August 25, 2016, 11:39:02 pm

Title: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: BigPaws on August 25, 2016, 11:39:02 pm
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
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: jamesL on August 26, 2016, 12:07:10 am
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)
Title: AW: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: eXpl0it3r on August 26, 2016, 12:24:06 am
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?
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: BigPaws on August 26, 2016, 12:25:11 am
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.

(http://image.prntscr.com/image/e09ae34329714475b0de0015cf716ab4.png)

(http://image.prntscr.com/image/5466fdabf16a44a59b32439d8890ba6a.png)

(http://image.prntscr.com/image/eb755abe5ea14361bb81142d5116e208.png)

(http://image.prntscr.com/image/c65b907711774dee8400488e2d37058d.png)
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: shadowmouse on August 26, 2016, 12:38:45 am
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.
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: BigPaws on August 26, 2016, 01:07:34 am
Changed
""sfml-xxx-d" for Debug, and "sfml-xxx" for Release."

just like official tutorial suggested. Didn't help with this issue sadly.
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: jamesL on August 26, 2016, 08:33:00 am
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)
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: BigPaws on August 26, 2016, 10:31:04 am
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 :/
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: eXpl0it3r on August 26, 2016, 10:45:02 am
Easiest solution is to get the SFML source and build SFML with whatever compiler you're using right now.
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: BigPaws on August 26, 2016, 11:01:50 am
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
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: eXpl0it3r on August 26, 2016, 11:09:40 am
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 (http://www.sfml-dev.org/tutorials/2.4/compile-with-cmake.php).
Title: Re: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_str
Post by: BigPaws on August 27, 2016, 06:11:09 pm
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.