Running linux gcc-compiled program under windows

16,849

Solution 1

No direct way. A Linux executable has a radically different format than Windows. There are several other options.

  • cygwin. Compile the program with GCC under cygwin. I believe that will build a windows exe that uses the cygwin compatibility layer.

  • install a VM like VBox. Install a Linux in the VBox. Run the program there.

  • http://www.andlinux.org has a framework for doing this. I've never tried it, but there is a video tutorial http://www.youtube.com/watch?v=nULDHPCm9p4.

Solution 2

Please don't tell me to recompile it under windows

You'll have to recompile it under Windows. Sorry!

If you really can't find a compiler with support for 128 bit integers you should use some assembler to replicate the instructions that you Linux compiler emits.

Solution 3

Since Windows 10 Anniversary Update, Windows is able to natively run Linux binaries via Windows Subsystem for Linux (WSL), commonly known as Bash on Ubuntu on Windows.

See https://msdn.microsoft.com/en-us/commandline/wsl

After installation, you can open a bash session, navigate to /mnt/<driveletter>/<path to your program> and run your executable as if you were running Linux.

Note: WSL is still beta.

Solution 4

It seems to me, that flinux could do it.

From the description:

... is a dynamic binary translator ... capable of running unmodified Linux binaries on Windows ...

Note: I've not tested this.

Share:
16,849

Related videos on Youtube

Matteo Monti
Author by

Matteo Monti

Updated on June 01, 2022

Comments

  • Matteo Monti
    Matteo Monti almost 2 years

    Ok, guys, hope this is quite a simple question: is there any way to run a C program compiled under linux with gcc on a windows operating system? Please don't tell me to recompile it under windows, since I already tried but looks like no c windows compiler has 128 bit native type, and using bignum libraries makes my program like 10 to 100 times slower. Is there any way to actually RUN the linux binary under windows? Someone told me something about cygwin, but I don't know where to get started with it. (My program should be portable as well, so I souldn't need to install programs and stuff on my machine).

    Thank you very much!! Matteo

  • Matteo Monti
    Matteo Monti almost 13 years
    So, if I compile the program under cygwin, it results in a .exe file that I can use on any windows computer if I put like "cygwin1.dll" in the same directory of the .exe?
  • Charlie Martin
    Charlie Martin almost 13 years
    the cygwin dll has to be someplace Windows can find it. honestly, I avoid windows and don't recall exactly howe to set that up.
  • Matteo Monti
    Matteo Monti almost 13 years
    Hi! I tried to compile it under cygwin, but...! Looks like it doesn't even recognize the __uint128_t identifier! I wonder... in wich version of cygwin were __uint128_t introduced? My current cygwin gcc version is 4.3.4...
  • Phil
    Phil over 7 years
    I have tested FLinux for running a command line Linux program and it worked. No need to recompile the program.
  • Phil
    Phil over 7 years
    No need to recompile using the FLinux (ForeignLinux) software, as explained in one of the answers below. FLinux does not support all the features of Linux. But for some command line program, I have tested it and it works. It can run a Linux binary file directly on Windows.