executable file compiled by MinGW x86_64-w64-mingw32 in Ubuntu not working on Windows

2.1k views Asked by At

I am trying to create a executable file works on Windows 64bit from linux.

I am using MXE to cross compile c file on my ubuntu server. And after I compile c file to .exe file, I move the file to my desktop(windows 10 64bit).

Here's what I did.

  1. installed mingw-w64

    sudo apt-get install mingw-w64

    sudo apt-get install gcc-mingw-w64

  2. I cloned the mxe git and set some attrs.

    git clone https://github.com/mxe/mxe.git

    cd mxe

    echo MXE_TARGETS=x86_64-w64-mingw32.static > settings.mk

    make cc

    echo 'export PATH="$PATH:$HOME/mxe/usr/bin"' >> ~/.bash_profile

  3. I created c file for test.

    cat<<'EOT' > test.c
    #include <stdio.h>
    void main()
    {
        printf("Hello World\n");
    }
    EOT
    
    
  4. I compiled c file to exe file.

    x86_64-w64-mingw32-gcc -o test.exe test.c

Finally I could get an exe file that I compiled by wingw, but when I try to open this file on my desktop Windows 10, it won't work. There's only a short blink when I open this exe file.

I tried x86_64-w64-mingw32.static-gcc to compile the file, but won't work.

x86_64-w64-mingw32.static-gcc: command not found
1

There are 1 answers

0
Brecht Sanders On

If you don't get an error, it probably works.

You created a console application, so it will open a console window, print to it and when the program finishes the console window will close. That's the short blink you're seeing.

Open a Command Prompt or PowerShell window and run your test.exe from there. Type the full path to test.exe, or drag test.exe on the console window and press Enter. When the program exits, the console will remain open and you will see the output of your application.