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 in Linux Administration by Korak
• 5,820 points
506 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 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 in Linux Administration by Rahul
• 9,240 points
57 views
0 votes
0 answers
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 in Linux Administration by Aditya
• 7,660 points
138 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
430 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
1,181 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 in Linux Administration by Soham
• 9,330 points
33 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 in Linux Administration by Aditya
• 7,660 points
37 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 in Linux Administration by Edureka
• 13,640 points
23 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 in Linux Administration by Rahul
• 3,380 points
37 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 in Linux Administration by Rahul
• 3,380 points
213 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP