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

Author Topic: Linker errors  (Read 4024 times)

0 Members and 1 Guest are viewing this topic.

MehdiBmm

  • Newbie
  • *
  • Posts: 5
    • View Profile
Linker errors
« on: December 04, 2015, 06:10:32 pm »
Hi there,
It's been a while that I was trying to use Sfml but was unable to get it working.
Today, I have used this http://www.sfml-dev.org/tutorials/2.2/start-cb.php, as I'm using Code:Blocks and Sfml version 2.3.
I did all what was described, but got many undefined errors:
(click to show/hide)
Is this because there is something missing ? (such opengl etc...because I didn't really understand the table of the dependencies.)
How to get it working ? I use Code:Blocks but I can also use Visual Studio 2015 and DevC++.
Thank you

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Linker errors
« Reply #1 on: December 04, 2015, 06:21:28 pm »
Your compiler must match the compiler the SFML binaries were built with. Additionally you need to link all of SFML's dependencies when you link statically against SFML as described in the tutorials.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MehdiBmm

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Linker errors
« Reply #2 on: December 05, 2015, 12:27:49 pm »
The compiler for Code:Blocks is Gcc and it's the one I took for SFML.
I choosed the dynamic linking and copied the bin content of SFML to the debug.
So, I don't know why it doesn't work, do you have an idea ?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linker errors
« Reply #3 on: December 05, 2015, 09:53:22 pm »
The compiler must match exactly, down to the last digit of the version number - you can't expect to be able to link code built with gcc 4.9.0 with code built with gcc 5.1.1 for example.
Also, for Windows there are multiple different builds of gcc available from different sources and they are not compatible (not even if the version number is the same).
You must build and link your code with the exact same build/version of the compiler that was used to build SFML. The easiest way to ensure this is usually to just compile SFML yourself from source with the same compiler you use for your application.
« Last Edit: December 05, 2015, 09:55:08 pm by Jesper Juhl »

MehdiBmm

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Linker errors
« Reply #4 on: December 10, 2015, 12:24:47 am »
I finally took the Visual Studio 14 2015 64 version, I have what It was told in the related page and followed instructions on a youtube video.
But I get two errors:
-#include <SFML/Graphics.hpp>': skipped when looking for precompiled header use
-unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
The second one didn't want to stop, even by including the stadfx.h, what should I do ? it's confusing.

Spirro

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Linker errors
« Reply #5 on: December 10, 2015, 12:57:15 am »
I finally took the Visual Studio 14 2015 64 version, I have what It was told in the related page and followed instructions on a youtube video.
But I get two errors:
-#include <SFML/Graphics.hpp>': skipped when looking for precompiled header use
-unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
The second one didn't want to stop, even by including the stadfx.h, what should I do ? it's confusing.

I will just say what others would here.  Youtube videos are rarely up to date.  Please follow the guides here:
http://www.sfml-dev.org/tutorials/2.3/compile-with-cmake.php

From my personal experience it is best to compile SFML on my own using the above guide.  That way I know the resulting binaries will work with my tool chain.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Linker errors
« Reply #6 on: December 10, 2015, 08:24:45 am »
Try to start with an empty project instead of the Win32 one, that way you won't have to deal with pre-compiled headers.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MehdiBmm

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Linker errors
« Reply #7 on: December 10, 2015, 12:17:53 pm »
I figured out how to disable precompiled headers, the linker has thrown new errors, it's a pain, every time something is fixed another issue appears.
I finally compiled the sources with Cmake for Code:Blocks MinGw.
This code compiles well:
(click to show/hide)
However, when I do the one the tutorial (that shows a green circle) I get a bunch of linker errors.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Linker errors
« Reply #8 on: December 10, 2015, 02:15:43 pm »
So you switched to Code::Blocks now?
If not, you can't build something for MinGW and expect it to use with Visual Studio. The example your showed "builds" because you just include a header and don't use anything of it, thus you don't have to link SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MehdiBmm

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Linker errors
« Reply #9 on: December 10, 2015, 02:38:17 pm »
No, I downloaded the already compiled sources for the Visual Studio, and for Code:Blocks I compiled myself with Cmake.
And still both of them aren't working.