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

Author Topic: [Solved] Unable to run statically compiled SFML with GCC  (Read 175 times)

0 Members and 2 Guests are viewing this topic.

ebots

  • Newbie
  • *
  • Posts: 11
    • View Profile
[Solved] Unable to run statically compiled SFML with GCC
« on: November 08, 2024, 08:30:22 am »
I have compiled SFML statically using GCC 13.1.0 from winlibs MinGW64
When I compile my source code, no errors are omitted, but when I go to run the executable, it exits with an error but there is no output

I have tried using the precompiled libraries from the SFML release, but it produces the same result

Code Used:
#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;
};
 

Compile Command:
Code: [Select]
g++ test.cpp -o test.exe -D SFML_STATIC -I SFML-2.6.1\include -L SFML-2.6.1\build\lib -l sfml-graphics-s -l sfml-window-s -l sfml-system-s -l opengl32 -l winmm -l gdi32
« Last Edit: November 08, 2024, 08:55:24 am by ebots »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11028
    • View Profile
    • development blog
    • Email
Re: Unable to run statically compiled SFML with GCC
« Reply #1 on: November 08, 2024, 08:33:39 am »
If you run it from the explorer, do you not get errors telling your that some DLL is missing?

You need  to provide the GCC/std libs.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ebots

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Unable to run statically compiled SFML with GCC
« Reply #2 on: November 08, 2024, 08:46:48 am »
I ran the executable from explorer and it said it could not find libgcc_s_seh-1.dll and libstdc++-6.dll, I found the libgcc dll but I cannot find the stdc++ dll with the -6 prefix at the end, only one without it within MinGW. I tried to link against the dll but Windows still says it cannot find that dll

ebots

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Unable to run statically compiled SFML with GCC
« Reply #3 on: November 08, 2024, 08:53:01 am »
I figured it out, I just had to add
Code: [Select]
-static-libstdc++ -static flags to my compile command, thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11028
    • View Profile
    • development blog
    • Email
Re: Unable to run statically compiled SFML with GCC
« Reply #4 on: November 08, 2024, 09:59:49 am »
I tried to link against the dll but Windows still says it cannot find that dll
You don't need to "link" them, but provide them next to your executable.

Or I guess link them statically which you figured out.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything