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

Author Topic: Troubles creating a portable version of MinGW with SFML, linking error  (Read 4380 times)

0 Members and 1 Guest are viewing this topic.

reportados123

  • Newbie
  • *
  • Posts: 18
    • View Profile
Hi, I have experience with C++ and the basics of SFML.

I would like to have MinGW and SFML on a USB Drive. What I've done is create a folder and moved all of the MinGW stuff to it. (C:/MinGW to the folder) Then, what I've done is download SFML 2.0 RC, the GCC DW2 version and extracted it. I put them both on the usb and start trying to get SFML to work, but I get a linking error.

I tried without using SFML, and compiling non-SFML related programs (such as the classic "Hello World!" program) and it worked fine. Only SFML (and possibly other ones too) doesn't work.

I try the following:

g++ test.cpp -ISFML/include/ -LSFML/lib/ -lsfml-graphics

and it gives me this error:

C:\Users\Joe\Desktop>g++ test.cpp -ISFML/include/ -LSFML/lib/ -lsfml-graphics
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x92): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x145): undefined reference to `_imp___ZN2sf6Window5closeEv'
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x15d): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x1e3): undefined reference to `_imp___ZN2sf6Window7displayEv'
C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o:test.cpp:(.text+0x1f2): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
c:/users/joe/desktop/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\Joe\AppData\Local\Temp\ccPRI8Sp.o: bad reloc address 0xe in section `.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]'
c:/users/joe/desktop/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Oh by the way, the reason why it says Desktop is because I'm testing it on the Desktop instead of the usb (it should work anyways, regardless of desktop or on usb stick.

I am running MSYS so I could easily change directories and then compile the code. Also, the code sample I'm using is:

#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

Something is wrong when it's trying to link SFML. Also, I've redownloaded SFML GCC DW2 and MinGW multiple times, it's not that. I'm probably doing something wrong that I'm not realizing, hopefully someone could help me out.

If you have any questions, please ask, thanks.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
« Last Edit: January 12, 2013, 08:16:13 am by binary1248 »
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

reportados123

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #2 on: January 12, 2013, 04:12:58 pm »
I am such an idiot! What I was missing was "-lsfml-window". Which is weird, because on my linux computer, when I compile, all I needed was -lsfml-graphics and didn't need to add in window. Now my program compiles, but there's one thing doesn't work, the program itself. So I'm using the following:

g++ test.cpp -o sfml-app -ISFML/include/ -LSFML/lib/ -lsfml-graphics -lsfml-window -lsfml-system

This compiles my program. I also included the dll's that was required for the program to run, which are:

libgcc_s_dw2-1.dll
libstdc++-6.dll
sfml-graphics-2.dll
sfml-system-2.dll
sfml-window-2.dll

However, when running the program, it just crashes immediately and says: "sfml-app.exe has stopped working. Windows can check online for a solution to the problem."

Can someone enlighten me on this? Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #3 on: January 12, 2013, 04:27:46 pm »
If you use gcc 4.7 you must recompile SFML.
Laurent Gomila - SFML developer

reportados123

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #4 on: January 12, 2013, 04:31:26 pm »
Ah I see, okay, I'll recompile SFML if that works. Also, is there any reason why it isn't compiled using GCC 4.7.2?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #5 on: January 12, 2013, 04:46:38 pm »
It's an old release (march 2012), the final release will have a package for gcc 4.7.
Laurent Gomila - SFML developer

reportados123

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #6 on: January 12, 2013, 06:07:24 pm »
Thanks, it works now! However, can someone explain why now it doesn't require libgcc_s_dw2-1.dll and libstdc++-6.dll? Also, is there a way to hide the command prompt that pops up after I open the program?
« Last Edit: January 12, 2013, 06:35:36 pm by reportados123 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11028
    • View Profile
    • development blog
    • Email
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #7 on: January 12, 2013, 06:17:31 pm »
However, can someone explain why now it doesn't require libgcc_s_dw2-1.dll and libstdc++-6.dll?
If you run it from with in the MSYS, then it will already have the compiler's binaries in PATH, which includes libgcc and libstdc++.
The other explanation would be, that the libs got linked statically.

Also, is there a way to hide the command prompt that pops up after I open the program?
You have to set the subsystem to windows instead of console and then link against sfml-main.
For debugging purposes I advise you though to keep the console, so you see SFML's, OpenGL's and your own error messages.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

reportados123

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #8 on: January 12, 2013, 06:38:00 pm »
However, can someone explain why now it doesn't require libgcc_s_dw2-1.dll and libstdc++-6.dll?
If you run it from with in the MSYS, then it will already have the compiler's binaries in PATH, which includes libgcc and libstdc++.
The other explanation would be, that the libs got linked statically.

Also, is there a way to hide the command prompt that pops up after I open the program?
You have to set the subsystem to windows instead of console and then link against sfml-main.
For debugging purposes I advise you though to keep the console, so you see SFML's, OpenGL's and your own error messages.

Ah I see, thanks! I was using MSYS, which is why it didn't complain.

And can you tell me how I can go about setting the subsystem to windows instead of console and then link against sfml main? And yes, for debugging purposes I will keep the console, but I need to know how to do this because I know some people will complain about seeing this command prompt being shown every time they run my program.

Thanks for the help.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11028
    • View Profile
    • development blog
    • Email
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #9 on: January 12, 2013, 07:07:49 pm »
And can you tell me how I can go about setting the subsystem to windows instead of console and then link against sfml main?
If you go with the terminal directly, then you'll have to add the compile flag: -mwindows and the linker flag lsfml-main.
So in the end your complete command would look like:
g++ test.cpp -o sfml-app -mwindows -ISFML/include/ -LSFML/lib/ -lsfml-graphics -lsfml-window -lsfml-system -lsfml-main

Btw. for the debug version, you'll also have to link against the debug SFML libraries (the ones with the suffix -d).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

reportados123

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Troubles creating a portable version of MinGW with SFML, linking error
« Reply #10 on: January 12, 2013, 07:35:09 pm »
Thanks for the help.