Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for mingw build #874

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Conversation

rofl0r
Copy link
Collaborator

@rofl0r rofl0r commented Dec 6, 2024

this allows to easily cross-compile the windows gui app for 32 or 64 bits even.

rofl0r added 16 commits December 6, 2024 01:46
In file included from CWindow.cpp:19:0:
CWindow.h:288:33: error: invalid pure specifier (only '= 0' is allowed) before ' token
  virtual DWORD ThreadFunc()=NULL;
                                 ^
mingw only supports the one-argument form of old windows.

fsnitroView.cpp: In function 'BOOL ViewFSNitroProc(HWND, UINT, WPARAM, LPARAM)':
fsnitroView.cpp:285:31: error: too many arguments to function 'int mkdir(const char*)'
         mkdir(tmp.c_str(),0777);
                               ^
the undef leads to the __stdcall attribute being stripped from all
functions, which in turn causes the symbols to not be found at link
time, as stdcall symbols have different name mangling.
this apparently is an extension of MSVC, and gcc disallows it.

replay.cpp: In function 'INT_PTR RecordDialogProc(HWND, UINT, WPARAM, LPARAM)':
replay.cpp:285:4: error: anonymous struct not inside named type
    };
    ^
In file included from /opt/mingw-w64/libexec/i686-w64-mingw32/include/minwindef.h:163:0,
                 from /opt/mingw-w64/libexec/i686-w64-mingw32/include/windef.h:,
                 from /opt/mingw-w64/libexec/i686-w64-mingw32/include/windows.h:69,
                 from replay.cpp:20:
replay.cpp:286:16: error: 'rtcMin' was not declared in this scope
    ZeroMemory(&rtcMin, sizeof(SYSTEMTIME));
                ^
replay.cpp:287:16: error: 'rtcMax' was not declared in this scope
    ZeroMemory(&rtcMax, sizeof(SYSTEMTIME));
                ^
directx/xma2defs.h:406:5: error: '__out' has not been declared

note that we have to undef the macros on leaving the header,
as these names are also used for some arguments in stdlibc++
headers.
../../frontend/modules/ImageOut.cpp:30:56: error: 'malloc' was not declared in this scope
../../lua-engine.cpp:1552:31: error: 'vscprintf' was not declared in this scope
  int len = vscprintf(fmt, list);
                               ^
File_Extractor/unrar/strfn.cpp: In function 'wchar etoupperw(wchar)':
File_Extractor/unrar/strfn.cpp:135:21: error: 'toupperw' was not declared in this scope
   return(toupperw(ch));
                     ^
File_Extractor/unrar/strfn.cpp: In function 'int wcsicompc(const wchar*, const wchar*)':
File_Extractor/unrar/strfn.cpp:240:28: error: 'wcsicomp' was not declared in this scope
   return wcsicomp(Str1,Str2);
                            ^
i686-w64-mingw32-windres: resources.rc:2140: syntax error
i686-w64-mingw32-windres: preprocessing failed.
mingw's windres chokes on backslashed path names, a CI run will show
whether MSVC's rc builder can deal with forward slashes, but typically
windows tools support both styles.
../../ROMReader.cpp: In function 'void* STDROMReaderInit(const char*)':
../../ROMReader.cpp:31:36: error: cannot convert 'stat*' to '_stat32*' for argument '2' to 'int _stat32(const char*, _stat32*)'
 #define stat(...) _stat(__VA_ARGS__)
                                    ^
../../utils/libfat/fatdir.cpp:37:21: fatal error: sys/dir.h: No such file or directory
 #include <sys/dir.h>
                     ^
../../gdbstub/gdbstub_internal.h:36:25: fatal error: sys/socket.h: No such file or directory
otherwise we get link errors like:
snddx.o:snddx.cpp:(.text+0x556): undefined reference to `DXGetErrorDescription8A(long)@4'
snddx.o:snddx.cpp:(.text+0x563): undefined reference to `DXGetErrorString8A(long)@4'

this also gets rid of the previous workaround.
mingw doesn't ship this header, so to make it compatible we have
to create the uuid symbols, otherwise we get the following link
errors:

sndxa2.o:sndxa2.cpp:(.text+0x35f): undefined reference to `_GUID const& __mingw_uuidof<IXAudio2>()'
sndxa2.o:sndxa2.cpp:(.text+0x366): undefined reference to `_GUID const& __mingw_uuidof<XAudio2>()'
@zeromus
Copy link
Contributor

zeromus commented Dec 6, 2024

as long as it doesn't break msvc. let me know when youre done

@rofl0r
Copy link
Collaborator Author

rofl0r commented Dec 6, 2024

should be complete from my side. you might want to try the aviout.cpp fix though; i'm not 100% sure it's correct, and avi recording crashes in the mingw build - though that might have other reasons. once it's merged i can set up a CI job

we need to use the mingw-provided headers, otherwise we'll run into
linker errors later on.
gcc chokes on this with:
aviout.cpp: In constructor 'NDSCaptureObject::NDSCaptureObject(size_t, size_t, const WAVEFORMATEX*)':
aviout.cpp:564:26: error: cannot call constructor 'NDSCaptureObject::NDSCaptureObject' directly
  this->NDSCaptureObject::NDSCaptureObject();
mingw's winnt.h uses FASTCALL for its own purposes, so depending on
the include order the code uses either mingw's definition, or the
one from types.h. that makes it almost impossible to reason which
definition ends up being used, even though it's of utmost importance
to have the jit perform correctly.
this, together with the renaming done in the previous commit, fixes
the jit from crashing when compiled with mingw for x86.
@rofl0r
Copy link
Collaborator Author

rofl0r commented Dec 6, 2024

ok, both aviout and jit are fixed now. the jit issue was caused by mingw having its own STDCALL macro - see 18f166b . for avi i found the proper way to call another constructor via delegation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants