mamedev / mame

MAME
https://www.mamedev.org/
Other
8.43k stars 2.04k forks source link

Cross compiling a Windows SDL version of MAME fails #4661

Closed katananja closed 5 years ago

katananja commented 5 years ago

mame0206-402-g95f817b54d Debian 9.6 X64 GCC 6.3.0 Build options: make clean && make TARGETOS=windows SUBTARGET=tiny OSD=sdl

SDL 2.0.5

sudo apt list --installed| grep sdl
libsdl2-dev/stable,now 2.0.5+dfsg1-2 amd64 [installed]
libsdl2-ttf-2.0-0/stable,now 2.0.14+dfsg1-1 amd64 [installed,automatic]
libsdl2-ttf-dev/stable,now 2.0.14+dfsg1-1 amd64 [installed]
sdl2-config --version
2.0.5

sdl2-config --libs
-L/usr/lib/x86_64-linux-gnu -lSDL2

sdl2-config --cflags
-I/usr/include/SDL2 -D_REENTRANT
locate libSDL2-2.0
/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so
/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
/usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.4.1
locate SDL.h
/home/mame/build/mame/3rdparty/SDL2/include/SDL.h
/home/mame/build/mame/build/generated/includes/SDL2/SDL.h
/usr/include/SDL2/SDL.h

Environment:

env|grep MINGW64 && env|grep MINGW32
MINGW64=/usr/x86_64-w64-mingw32
MINGW32=/usr/i686-w64-mingw32

First try:

Compiling src/osd/modules/input/input_common.cpp...
../../../../../src/osd/modules/input/input_common.cpp:36:22: fatal error: SDL2/SDL.h: No such file or directory
 #include <SDL2/SDL.h>
                      ^
compilation terminated.
osd_sdl.make:921: recipe for target '../../../../mingw-gcc/obj/x64/Release/osd_sdl/src/osd/modules/input/input_common.o' failed
make[2]: *** [../../../../mingw-gcc/obj/x64/Release/osd_sdl/src/osd/modules/input/input_common.o] Error 1
Makefile:19: recipe for target 'osd_sdl' failed
make[1]: *** [osd_sdl] Error 2
makefile:1055: recipe for target 'windows_x64' failed
make: *** [windows_x64] Error 2

Second try: make TARGETOS=windows SUBTARGET=tiny OSD=sdl REGENIE=1 USE_BUNDLED_LIB_SDL2=0

Linking sdlmametiny64.exe...
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lImm32
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lVersion
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lOle32
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lOleAut32
collect2: error: ld returned 1 exit status
mametiny.make:270: recipe for target '../../../../../sdlmametiny64.exe' failed
make[2]: *** [../../../../../sdlmametiny64.exe] Error 1
Makefile:103: recipe for target 'mametiny' failed
make[1]: *** [mametiny] Error 2
makefile:1055: recipe for target 'windows_x64' failed
make: *** [windows_x64] Error 2

Looks like this is a case-sensitive issue at scripts/src/osd/sdl.lua starting at line 55:

    if _OPTIONS["targetos"]=="windows" then
        if _OPTIONS["with-bundled-sdl2"]~=nil then
            configuration { "mingw*"}
                links {
                    "SDL2",
                    "Imm32",
                    "Version",
                    "Ole32",
                    "OleAut32",
                }

This goes beyond me, maybe other fixes might be needed. Thank you.

cuavas commented 5 years ago

Are you setting OVERRIDE_CC and OVERRIDE_CXX to point to the cross-compilers? Are you setting CROSS_BUILD to enable separate host/target compilers?

cuavas commented 5 years ago

I just tested it and cross-compilation works as expected. Additionally, @couriersud has been using cross-compilation successfully over the past few days. If you're having trouble using a feature please ensure you understand how it's supposed to work before opening an issue. The issue tracker is not a help forum.

katananja commented 5 years ago

According to toolchain.lua at this specific code starting at line 275 to 293:

        if "mingw64-gcc" == _OPTIONS["gcc"] then
            if not os.getenv("MINGW64") then
                print("Set MINGW64 envrionment variable.")
            end
            if toolchainPrefix == nil or toolchainPrefix == "" then
                toolchainPrefix = "$(MINGW64)/bin/x86_64-w64-mingw32-"
            end
            premake.gcc.cc  = toolchainPrefix .. "gcc"
            premake.gcc.cxx = toolchainPrefix .. "g++"
-- work around GCC 4.9.2 not having proper linker for LTO=1 usage
            local version_4_ar = str_to_version(_OPTIONS["gcc_version"])
            if (version_4_ar < 50000) then
                premake.gcc.ar  = toolchainPrefix .. "ar"
            end
            if (version_4_ar >= 50000) then
                premake.gcc.ar  = toolchainPrefix .. "gcc-ar"
            end
            location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-mingw64-gcc")
        end

It show that it will setup and use the cross-compilers once the MINGW64 environment is set and the code will handle the rest, so it will resolve $(MINGW64)/bin/x86_64-w64-mingw32- in to the full path of /usr/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc and /usr/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++ in my case. I only use OVERRIDE_CC and OVERRIDE_CXX to build MAME with Clang.

I did run another test with OVERRIDE_CC=/usr/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc and OVERRIDE_CXX=/usr/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++ it return the exact same error since looks like is a link and not compiling issues.

Looks like it's the same issue as 9c9fe82d4f811fff6639df5b286d8c7da13818a9, it might be necessary to change Imm32 to imm32, Version to version, Ole32 to ole32 so on and so forth.

This errors only happen with a SDL version of MAME, without it, cross-compiling a non-SDL version for windows works fine. The CROSS_BUILD=1 is set in all cross-compilations.

katananja commented 5 years ago

I just tested it and cross-compilation works as expected. Additionally, @couriersud has been using cross-compilation successfully over the past few days. If you're having trouble using a feature please ensure you understand how it's supposed to work before opening an issue. The issue tracker is not a help forum.

The cross-compilation is not broken @cuavas, I can compile a MAME for windows just fine, the issue is with the SDL version of it, the linker can't link using Imm32 and other libs because it's case-sensitive.

cuavas commented 5 years ago

OK, I checked made the library names lowercase for libraries that are lowercase in system32 on my Windows system, documented the cross-compilation options (was doing that already), and made USE_BUNDLED_LIB_SDL2 do the right thing for both 0 and 1 (0 doesn't change the default) -- see 8ffff5d2d3bcebbdbefec2508ddd2ecd264a399a

katananja commented 5 years ago

Thank you.