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

Author Topic: Linker error I don't understand  (Read 2074 times)

0 Members and 4 Guests are viewing this topic.

distagon35

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Linker error I don't understand
« on: December 31, 2017, 11:24:19 am »
Hello,
unable to compile the "opengl" example of SFML.


Windows 7,
SFML 2.3.2 - 32 bit,
TDM with gcc 4.8.1
Codeblocks 16.01

I followed exactly the instructions on the SFML tutorial page. All needed files are availabe, and I think codeblocks is well configured. The first example of the tutorial compiles and runs fine, the SFML example "window" too. But trying to compile the example "opengl" I get the error messages below. Just the lines where some ressources have to be loaded.

Code: [Select]
-------------- Build: Debug in SFML01 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -g -IE:\Projekte\Codeblocks\include -c E:\Projekte\Codeblocks\SFML01\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LE:\Projekte\Codeblocks\lib -o bin\Debug\SFML01.exe obj\Debug\main.o   -lopengl32 -lsfml-audio-d -lsfml-graphics-d -lsfml-window-d -lsfml-system-d
obj\Debug\main.o: In function `main':
E:/Projekte/Codeblocks/SFML01/main.cpp:27: undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'
E:/Projekte/Codeblocks/SFML01/main.cpp:33: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
E:/Projekte/Codeblocks/SFML01/main.cpp:52: undefined reference to `_imp___ZN2sf5Image12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
4 error(s), 0 warning(s) (0 minute(s), 0 second(s))

The same errors I got by trying other combinations of SFML and gcc. On Linux this example works without any troubles.





eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10990
    • View Profile
    • development blog
    • Email
Re: Linker error I don't understand
« Reply #1 on: December 31, 2017, 01:02:16 pm »
Why are you using the outdated SFML 2.3.2 instead of 2.4.2 or master?

The latest Code::Blocks version ships with the TDM 4.9.2 compiler which is not compatible with the binaries for TDM 4.8.1.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

distagon35

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Linker error I don't understand
« Reply #2 on: December 31, 2017, 05:28:52 pm »
Ok, I've installed TDM with gcc 4.9.2 and the SFML version 2.4.2.
Just the same error message.  3 different calls of "loadFromFile", and all don't work.

Code: [Select]
        if (!backgroundTexture.loadFromFile("background.jpg"))
            return EXIT_FAILURE;

        if (!font.loadFromFile("sansation.ttf"))
            return EXIT_FAILURE;

        if (!texture.loadFromFile("texture.jpg"))
            return EXIT_FAILURE;

BTW: I don't believe that these errors depend on a wrong version. On Linux I use Codeblocks 16.01 together with SFML 2.3.2 (because it's in the Ubuntu repository), and - as I said - it works well.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10990
    • View Profile
    • development blog
    • Email
Re: Linker error I don't understand
« Reply #3 on: December 31, 2017, 06:00:32 pm »
BTW: I don't believe that these errors depend on a wrong version. On Linux I use Codeblocks 16.01 together with SFML 2.3.2 (because it's in the Ubuntu repository), and - as I said - it works well.
It has nothing to do with Code::Blocks, as C::B is just an IDE that uses a compiler. It only matters in the sense that by default C::B on Windows ships with TDM 4.9.2.
And it's also not that SFML doesn't support any other compiler or that SFML 2.3.2 wouldn't work with TDM 4.9.2, it's just that we don't provide the pre-compiled binaries that exactly match the compiler version.

The error simply implies that the runtime version specifically std:: string isn't the same for the application and for the version that was used in SFML.
The easiest solution is to simply rebuild SFML with CMake, your compiler and the same compiler flags (e.g. C++11 flag).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

distagon35

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Linker error I don't understand
« Reply #4 on: January 01, 2018, 11:12:31 am »
And so I'm going to learn CMake. Fortunately there is a tutorial in the "getting started" section of SFML.
Oh, I like coding, but I hate all the configuration und installation work. Nevertheless thanks and a happy new year.

distagon35

 

anything