SFML community forums

Help => General => Topic started by: MaxPain on February 13, 2021, 07:15:20 am

Title: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 13, 2021, 07:15:20 am
Hello everyone!

I use SFML on MacOS and I want to compile it for Windows. I installed MinGW via HomeBrew and compile my program, but when I try to start it on Windows there is an error "libgcc_s_dw2.dll is missing".

I have already used -static, -static-libgcc and -static-libstd++ options. What is wrong? How can I fix it?
Maybe I should just download this dll manually and put in my execution's dir, but I think it is not the best way.
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 13, 2021, 01:04:00 pm
You also need to build SFML with the mentioned static options, otherwise SFML will still rely on the dynamic runtime libraries.
Alternatively, you can just ship your application with the missing DLL from the MinGW installation (check the bin directory).
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 13, 2021, 03:44:00 pm
There is no libgcc_s_dw2 in MinGW bin files, probably because its version for MacOS.

And I did not understand what it means to static build SFML, after all, I'm already doing it.

"PATH"/i686-w64-mingw32-g++ main.cpp   -L "PATH"/SFML-2.5.1-win32/lib -o test.exe -static -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system -I "PATH"/SFML-2.5.1-win32/include
 

The folder is named so because this is the version for Windows32

One more thing: if I use -lsfml-*-s to link it static, it says "Undefined reference to *Some SFML thing*", if I read it correctly, it does not find the code itself.
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 13, 2021, 04:00:55 pm
Code: [Select]
[quote author=MaxPain link=topic=27887.msg175352#msg175352 date=1613227440]
There is no libgcc_s_dw2 in MinGW bin files, probably because its version for MacOS.
Maybe it's not in the bin directory, but it should exist somewhere, since it's linking it. Unless they provide an additional runtime package or similar.

And I did not understand what it means to static build SFML, after all, I'm already doing it.
You're link SFML and not building it. In order to build SFML, you need to get SFML's source code, generate a make file with CMake and build it.

One more thing: if I use -lsfml-*-s to link it static, it says "Undefined reference to *Some SFML thing*", if I read it correctly, it does not find the code itself.
When linking SFML statically, you also need to link SFML's dependencies (freetype, vorbis, flac, ogg, etc).

Personally, I highly recommend to build natively on Windows rather than cross-compilation, as it's usually easier to solve issues on a native setup rather than in a cross-compilation.
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 14, 2021, 09:42:10 am
I downloaded source code, built it with BUILD_SHARED_LIBS=FALSE and did this

i686-w64-mingw32-g++ main.cpp -o test.exe -static -I SFML-2.5.1/include -L SFML-2.5.1/lib -L SFML-2.5.1/extlibs/libs-mingw/x86 -lopengl32 -lgdi32 -lwinmm -lfreetype -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lws2_32 -lsfml-audio-s -lsfml-graphics-s -lsfml-system-s -lsfml-window-s

But it still says undefined reference, and I don't see gdi32, winmm, opengl32 and ws2_32 in extlibs folder.

I realized that it is more convenient to build on Windows, but I want to try because I'm the beginner.
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 14, 2021, 04:46:31 pm
But it still says undefined reference, and I don't see gdi32, winmm, opengl32 and ws2_32 in extlibs folder.
Those are system libs and should come with the compiler as well.
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 16, 2021, 01:15:13 pm
Alright, I did everything you said, I link every single library and even tried to build it on Windows but it still says
"Undefined reference". What I have to do?
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 16, 2021, 07:07:04 pm
Well "undefined reference" is not just a magic set of words, but it's an actual error message that tells you exactly which references were unable to resolve while linking.

There can be various things, so you need to provide the detailed errors.

Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 20, 2021, 04:46:23 pm
Alright, I almost done it

i686-w64-mingw32-g++ main.cpp -DSFML_STATIC  -static -L SFML-2.5.1-win32/lib -o test.exe
 -lws2_32 -lopengl32 -lgdi32 -lwinmm -lfreetype -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lopenal32 -lsfml-audio-s -lsfml-graphics-s -lsfml-window-s -lsfml-system-s
 -I SFML-2.5.1-win32/include -v

And I get something like that

/usr/local/Cellar/mingw-w64/8.0.0_3/toolchain-i686/bin/i686-w64-mingw32-ld: SFML-2.5.1-win32/lib/libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.cpp:(.text+0x2d79): undefined reference to `_imp__joyGetPosEx@8'
/usr/local/Cellar/mingw-w64/8.0.0_3/toolchain-i686/bin/i686-w64-mingw32-ld: SFML-2.5.1-win32/lib/libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.cpp:(.eh_frame+0x83): undefined reference to `__gxx_personality_v0'
/usr/local/Cellar/mingw-w64/8.0.0_3/toolchain-i686/bin/i686-w64-mingw32-ld: SFML-2.5.1-win32/lib/libsfml-window-s.a(Joystick.cpp.obj):Joystick.cpp:(.text+0x192): undefined reference to `_Unwind_Resume'
/usr/local/Cellar/mingw-w64/8.0.0_3/toolchain-i686/bin/i686-w64-mingw32-ld: SFML-2.5.1-win32/lib/libsfml-window-s.a(Joystick.cpp.obj):Joystick.cpp:(.eh_frame+0x11b): undefined reference to `__gxx_personality_v0'

All the libraries are in place
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 20, 2021, 07:47:06 pm
Since SFML depends on all the other libraries, SFML needs to be listed before the other libraries.
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 21, 2021, 06:36:41 am
Right?

/usr/local/Cellar/mingw-w64/8.0.0_3/bin/i686-w64-mingw32-g++ main.cpp -DSFML_STATIC  -static  -L SFML-2.5.1-win32/lib -o test.exe -lsfml-audio-s -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lws2_32 -lopengl32 -lgdi32 -lwinmm -lfreetype -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lopenal32 -I SFML-2.5.1-win32/include -v
 

But it doesn't work.
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 21, 2021, 01:37:04 pm
And what's the error now? :)
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 22, 2021, 05:38:36 am
Same :-\

Mostly "undefined reference to Unwind_Resume"
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 22, 2021, 08:11:58 am
Did you build SFML yourself? As the download page says in the prominently placed red box, compilers need to match 100% and we currently don't have any builds for the compiler you're using.
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 22, 2021, 09:21:27 am
I am using the only MinGW that I could download for Mac as I know version is 8.0.0_3 and GCC is 10.2.0.
On one of SFML pages I read 32bit version will be able to run on 64bit architecture so I decided to compile 32bit version, I tried to link libraries from SFML source code, but compiler said "unrecognized file format" apparently because it is 64bit then I need 32bit, that is why I downloaded a SFML-32bit for MinGW and now I have these errors.

I hardly will get MinGW version indicated on SFML download page.
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 22, 2021, 09:31:36 am
Then as I said, you need to compile SFML yourself.
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 22, 2021, 04:22:50 pm
How should i do this to avoid getting an error about Unrecognized file format?

Even I try to build self-build SFML version with 64bit compiler it says "undefined reference to SFML thing", I am sick of it. :'(
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 22, 2021, 08:37:08 pm
Personally, I wouldn't recommend cross-compilation, since it can be a lot of pain to get working properly and running Windows in a VM or on a different machine has also other benefits.

If you do want to keep cross-compiling, you'll need to get cmake, the SFML source code (https://github.com/SFML/SFML), configure CMake to use your MinGW compiler and follow the CMake tutorial (https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php) on build SFML as a library with your current compiler.
Or did you actually already do that? Your post always left me a bit inconclusive about this.

I realized that it is more convenient to build on Windows, but I want to try because I'm the beginner.
Nothing is stopping you from trying stuff, but it's usually better to start on an easy level as a beginner, until you're more familiar with a topic and can understand why something is or isn't working on your own.
You also don't pick the hardest possible game mode and then complain and give up because you can't finish the first level, since you don't understand the required mechanics. ;)
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 23, 2021, 07:11:29 am
Fine, let's s deal with it now  :).

Cmake doesn't see my MinGW as generator even it's bin in path variables. Maybe cmake need special files that are not there.
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 23, 2021, 07:51:31 am
For CMake you apparently habe to use a toolchain file and tell CMake you're cross-compiling.

https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling
https://metricpanda.com/rival-fortress-update-11-cross-compiling-for-three-platforms/

Feel free to google more along the lines of "macOS cmake cross-compiling"
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 23, 2021, 09:49:02 am
I made the toolchain... And error

CMake Error at /Applications/CMake.app/Contents/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "/usr/local/Cellar/mingw-w64/8.0.0_3/bin/i686-w64-mingw32-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Downloads/SFML-2.5.1-new/CMakeFiles/CMakeTmp
   
    Run Build Command(s):/usr/bin/make -f Makefile cmTC_4739f/fast && /Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/cmTC_4739f.dir/build.make CMakeFiles/cmTC_4739f.dir/build
    Building C object CMakeFiles/cmTC_4739f.dir/testCCompiler.c.obj
    /usr/local/Cellar/mingw-w64/8.0.0_3/bin/i686-w64-mingw32-gcc    -o CMakeFiles/cmTC_4739f.dir/testCCompiler.c.obj -c /Users/maxroschupkin/Downloads/SFML-2.5.1-new/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_4739f.exe
    /Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/cmTC_4739f.dir/link.txt --verbose=1
    /Applications/CMake.app/Contents/bin/cmake -E rm -f CMakeFiles/cmTC_4739f.dir/objects.a
    /usr/bin/ar cr CMakeFiles/cmTC_4739f.dir/objects.a @CMakeFiles/cmTC_4739f.dir/objects1.rsp
    ar: @CMakeFiles/cmTC_4739f.dir/objects1.rsp: No such file or directory
    make[1]: *** [cmTC_4739f.exe] Error 1
    make: *** [cmTC_4739f/fast] Error 2
   
   

 

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:45 (project)

Upd: Fixed ;D
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 23, 2021, 10:02:26 am
Now I need mingw32-make, where can I find it?
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 23, 2021, 11:46:58 am
It might just be called make with your MinGW version.
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 23, 2021, 11:51:59 am
Nope, there is nothing like make or cmake thing at all.
Title: Re: libgcc_s_dw2.dll is missing
Post by: eXpl0it3r on February 23, 2021, 12:56:46 pm
Maybe it needs to be installed first.
Title: Re: libgcc_s_dw2.dll is missing
Post by: MaxPain on February 27, 2021, 06:46:14 am
Everything is done.
First thing I create the CMake toolchain for cross compile

# Sample toolchain file for building for Windows

set(CMAKE_SYSTEM_NAME Windows)
#set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
#or 32 bit
set(TOOLCHAIN_PREFIX i686-w64-mingw32)

# cross compilers to use for C, C++
set(CMAKE_C_COMPILER     "/usr/local/Cellar/mingw-w64/8.0.0_3/bin/${TOOLCHAIN_PREFIX}-gcc")
set(CMAKE_CXX_COMPILER   "/usr/local/Cellar/mingw-w64/8.0.0_3/bin/${TOOLCHAIN_PREFIX}-g++")


# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Then I use CMake to configure SFML source files

cmake ./ -DCMAKE_TOOLCHAIN_FILE=Path/to/toolchain/WindowsTool.cmake
 

Then just make it and compile

/usr/local/Cellar/mingw-w64/8.0.0_3/bin/i686-w64-mingw32-g++ main.cpp -DSFML_STATIC -static -L SFML-2.5.1-2/extlibs/libs-mingw/x86 -L SFML-2.5.1-2/lib -o test.exe -lsfml-audio-s -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lws2_32 -lopengl32 -lgdi32 -lwinmm -lfreetype -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lopenal32 -I SFML-2.5.1-2/include -v
 

Thanks eXpl0it3r for help :D