Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 980 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compile executable for Windows with GCC with Linux Subsystem?

#1
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 ?
Reply

#2
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.
Reply

#3
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.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through