How to compile executable for Windows with GCC with Linux Subsystem

0 votes

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 testing purposes:

#include <stdio.h>
int main(void){
    printf("Hello\n");
    return 0;
}

And compiled it with gcc -c main.c but the execute (Linux only) main.o is generated. If I run it ./main.o, it displays Hello.

My question is, how can I compile main.c so that Windows can run it? Basically, how do you generate a *.exe file with GCC in Linux Subsystem ?

Jun 20, 2022 in Linux Administration by Korak
• 5,820 points
5,223 views

1 answer to this question.

0 votes

Linux Subsystem fills in as a Linux-PC. You can run Linux executables inside it and default gcc makes Linux executables.

To make Windows executables, you want to introduce mingw cross-compiler:

sudo adept get introduce mingw-w64

Then you can make 32-digit Windows executable with:

i686-w64-mingw32-gcc - o main32.exe main.c
answered Jun 20, 2022 by Rahul
• 3,380 points

Related Questions In Linux Administration

0 votes
0 answers

How to compile for Windows on Linux with gcc/g++?

I have written some effects in C++ ...READ MORE

Apr 13, 2022 in Linux Administration by Rahul
• 9,680 points
724 views
0 votes
0 answers

How to create shortcut icons for Windows, MacOS and Linux applications bundled with PyInstaller

I am building a Python application bundled ...READ MORE

Apr 26, 2022 in Linux Administration by Edureka
• 13,690 points
847 views
0 votes
0 answers

failure to compile imgui, glfw, opengl on linux with gcc 11.2

I've recently started coding with c++ and ...READ MORE

Apr 14, 2022 in Linux Administration by Aditya
• 7,680 points
823 views
0 votes
1 answer

How to find the group associated with a user in linux?

To list all the groups groups or to list ...READ MORE

answered Jun 21, 2019 in Linux Administration by DareDev
• 6,890 points
906 views
0 votes
1 answer

How to create nested directories with a single command in linux?

Try this command. mkdir -p /parent_dir/son_dir READ MORE

answered Oct 19, 2020 in Linux Administration by anonymous
• 19,610 points
2,119 views
0 votes
0 answers

How do I copy folder with files to another folder in Unix/Linux?

I am having some issues copying a ...READ MORE

Apr 13, 2022 in Linux Administration by Soham
• 9,710 points
351 views
0 votes
0 answers

How to convert a PDF into JPG with command line in Linux?

What are fast and reliable ways for ...READ MORE

Apr 14, 2022 in Linux Administration by Aditya
• 7,680 points
550 views
0 votes
0 answers

How do I copy folder with files to another folder in Unix/Linux?

I am having some issues to copy ...READ MORE

Apr 21, 2022 in Linux Administration by Edureka
• 13,690 points
379 views
0 votes
1 answer

Why do you need to put #!/bin/bash at the beginning of a script file?

It's a show so the *nix shell ...READ MORE

answered Jun 20, 2022 in Linux Administration by Rahul
• 3,380 points
1,084 views
0 votes
1 answer

How do you copy and paste into Git Bash

Press Insert. Likewise, to duplicate from the window, ...READ MORE

answered Jun 20, 2022 in Linux Administration by Rahul
• 3,380 points
1,786 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP