SFML static linking problem: sfml-system-2.dll not found

2

Quick Summary

I have a very simple SFML application that I'm trying to cross-compile to Windows, from Linux. I am trying to statically link the SFML libraries with the application.

However, when I run the compiled application in a Windows 10 Virtual Machine, I get DLL import errors: "The code execution cannot proceed because *.dll was not found. Reinstalling the program may fix this issue."

Some of the .dll files that were missing are: sfml-system-2.dll, sfml-window-2.dll etc.

Source Code

Here is the program I am trying to statically link:

// main.cpp
#include <SFML/Graphics.hpp>

int main(void) {
    sf::RenderWindow window(sf::VideoMode(800, 600), "Hello World!");
    sf::CircleShape circle(600.f / 2.f, 60);

    window.setFramerateLimit(60);

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            switch (event.type) {
                case sf::Event::Closed:
                    window.close();
                    break;
            }
        }

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

    return 0;
}

How I compiled

x86_64-w64-mingw32-g++ ./main.cpp -lsfml-system -lsfml-window -lsfml-graphics -static -static-libgcc -static-libstdc++

The compilation succeeds, and outputs a file: "a.exe"

As you can see, I'm using Mingw32, and I'm passing the -static parameter, which usually works on my other C++ programs, but it seems like SFML isn't successfully being statically linked.

My Environment

I'm thinking I might have the wrong environment for cross compiling SFML? I downloaded SFML 2.5.1 (GCC 7.3.0 MinGW (SEH) - 64-bit) from sfml-dev.org, placed the shared-object files into /usr/x86_64-w64-ming32/lib/, and then placed the include files into /usr/x86_64-w64-mingw32/include/.

What I tried

I tried taking the Windows SFML binaries (sfml-system-2.dll, sfml-window-2.dll, etc.) and placing them in the same directory as the application. They were successfully found & imported but then, I got an execution error: "The application was unable to start correctly (0xc000007b).". No idea what that means, but I assume it can be fixed by statically linking SFML.

I apologize if this is a nooby question, or if I'm doing something obviously wrong! I'm quite inexperienced with cross-compilation. Cheers!

c++
cross-compiling
sfml
static-linking
asked on Stack Overflow Aug 21, 2019 by 0wzk

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0