How to compile executable for Windows with GCC with Linux Subsystem?

前端 未结 2 1617
傲寒
傲寒 2020-12-04 07:20

Windows 10 Anniversary Update includes the Linux Subsystem for Ubuntu. I installed gcc with sudo apt-get install gcc.

I wrote some simple C code for tes

相关标签:
2条回答
  • 2020-12-04 07:22

    If you compile using gcc on linux it will produce an ELF file not a PE (what windows understand) file

    To compile a program for windows inside linux you can use mingw.

    0 讨论(0)
  • 2020-12-04 07:45

    Linux Subsystem works as a Linux-computer. You can only run Linux executables inside it and default gcc creates Linux executables.

    To create Windows executables, you need to install mingw cross-compiler:

    sudo apt-get install mingw-w64
    

    Then you can create 32-bit Windows executable with:

    i686-w64-mingw32-gcc -o main32.exe main.c
    

    And 64-bit Windows executable with:

    x86_64-w64-mingw32-gcc -o main64.exe main.c
    

    Note that these Windows executables will not work inside Linux Subsystem, only outside of it.

    0 讨论(0)
提交回复
热议问题