-
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.
-
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).
-
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.
-
[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.
-
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.
-
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.
-
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?
-
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.
- Missing source file
- Wrong header include
- Linked incompatible/different runtimes
- Missing dependency
- Wrong link order
- Linking static without having SFML_STATIC defined
- Linking dynamic while having SFML_STATIC defined
-
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
-
Since SFML depends on all the other libraries, SFML needs to be listed before the other libraries.
-
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.
-
And what's the error now? :)
-
Same :-\
Mostly "undefined reference to Unwind_Resume"
-
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.
-
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.
-
Then as I said, you need to compile SFML yourself.
-
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. :'(
-
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. ;)
-
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.
-
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"
-
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
-
Now I need mingw32-make, where can I find it?
-
It might just be called make with your MinGW version.
-
Nope, there is nothing like make or cmake thing at all.
-
Maybe it needs to be installed first.
-
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