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

Author Topic: Undefined references with MinGW 4.9.0  (Read 2698 times)

0 Members and 1 Guest are viewing this topic.

Xilen

  • Newbie
  • *
  • Posts: 14
    • View Profile
Undefined references with MinGW 4.9.0
« on: July 13, 2014, 01:05:31 am »
I really dislike posting here about all my problems but I've been having this one all day.
I just get a bunch of undefined references to everything in SFML.
I'm using the latest nightly build of SFML and MinGW.

Command line:
g++ main.cpp -DSFML_STATIC -IC:\SFML\include -LC:\SFML\lib

Minimal code
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640,480), "Test", sf::Style::Titlebar);

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

}

No idea what's wrong, help?

krzat

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Undefined references with MinGW 4.9.0
« Reply #1 on: July 13, 2014, 01:15:10 am »
You forgot -lsfml-graphics -lsfml-window -lsfml-system
g++ main.cpp -DSFML_STATIC -IC:\SFML\include -LC:\SFML\lib -lsfml-graphics -lsfml-window -lsfml-system
SFML.Utils - useful extensions for SFML.Net

Xilen

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Undefined references with MinGW 4.9.0
« Reply #2 on: July 13, 2014, 01:58:52 am »
Thanks for that! But the thing is, now when I launch the app I get this:
The program can't start because libgcc_s_sjlj-1.dll is missing from your computer.

Edit: I've tried -static and -static-libgcc but neither worked, same error.
« Last Edit: July 13, 2014, 02:09:37 am by Xilen »

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Undefined references with MinGW 4.9.0
« Reply #3 on: July 13, 2014, 02:13:10 am »
You downloaded a version of SFML that was compiled with a different kind of compiler, I'd recommend compiling SFML from scratch.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Undefined references with MinGW 4.9.0
« Reply #4 on: July 13, 2014, 02:17:48 am »
dabbertorres is correct. You need a version of SFML that has been compiled with the *exact* same compiler that you use to build your own code.
The tutorial even say this in a big red box:
Quote
There are multiple variants of gcc for Windows, which are incompatible with each other (different exception management, threading model, etc.). Make sure that you pick up the right package according to the version that you use. If you don't know, check which of the libgcc_s_sjlj-1.dll or libgcc_s_dw2-1.dll file you have in your MinGW/bin folder. If you're using the version of MinGW shipped with Code::Blocks, you probably have a SJLJ version.
If you feel like your version of gcc can't work with the precompiled SFML libraries, don't hesitate to recompile SFML, it's not complicated.

Xilen

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Undefined references with MinGW 4.9.0
« Reply #5 on: July 13, 2014, 02:28:47 am »
IT WORKS! Thanks for all the help! I recompiled from source and it worked.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Undefined references with MinGW 4.9.0
« Reply #6 on: July 13, 2014, 02:41:45 am »
That's good to hear. Thank you for letting people know that you solved your problem.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Undefined references with MinGW 4.9.0
« Reply #7 on: July 13, 2014, 02:31:10 pm »
Compiling from source is always a good idea, but for my taste the jump to incompatible compilers has been made too fast, because there's only one rather subtle indication that the compiler isn't the same as the I used for the Nighly Builds.

krzat's answer is only partically true, since he linked the dynamic libraries, but still defined SFML_STATIC. When linking SFML static, you of course have to use the libs with the -s suffix. But it seems Xilen figured that out on his own.

If you're missing a DLL it doesn't mean that your compiler is incompatible. Also if you link against the static SFML libraries which linked dynamically against the runtime libraries, you'll still need to ship the runtime library DLLs, regardless if you link them statically into your application. My Nightly Builds however always ship with the static libraries for which the runtime library was linked statically, but since there's a name clash they get moved into the directory lib/static-std.

Now the one indication that you might be using a different compiler than I used is: I've moved from SJLJ to DWARF2 regarding the exception handling, as such your application shouldn't be looking for libgcc_s_sjlj-1.dll.

So don't always jump to conclusions and if you do so you might want to give a more detailed reason. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/