mingw installation on Linux mingw installation on Linux linux linux

mingw installation on Linux


Install the toolchain with wine64 (for running Windows executables):

sudo apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 wine64

Take an example program hello.c:

#include <stdio.h>int main() {    printf("Hello world!\n");}

Compile:

x86_64-w64-mingw32-gcc -g -o hello hello.c

Check the result:

file hello.exe

Which should output something like this:

hello.exe: PE32+ executable (console) x86-64, for MS Windows

Run:

wine64 ./hello.exeHello world!

There is also gdb-mingw-w64 providing /usr/bin/x86_64-w64-mingw32-gdb but I could not figure out how it works (when I try it says Don't know how to run. Try "help target".).

One can use /usr/share/win64/gdbserver.exe (from gdb-mingw-w64-target package) to remote-cross-debug the windows binaries on Linux. For example:

/usr/share/win64/gdbserver.exe localhost:1234 ./hello.exeListening on port 1234

Then open regular gdb session:

gdb -q hello.exeReading symbols from hello.exe...(gdb) target remote localhost:1234Remote debugging using localhost:1234warning: Could not load shared library symbols for 4 libraries, e.g. C:\windows\system32\ntdll.dll.Use the "info sharedlibrary" command to see the complete listing.Do you need "set solib-search-path" or "set sysroot"?0x000000007bcddf65 in ?? ()(gdb) b mainBreakpoint 1 at 0x40159c: file hello.c, line 2.(gdb) cContinuing.Breakpoint 1, main () at hello.c:22   int main() {(gdb) n3       printf("Hello world!\n");(gdb) n4   }(gdb) cContinuing.[Inferior 1 (Remote target) exited normally]