7

Is there any way to convert a Linux binary file to windows exe file? For example if in Linux create a very simple binary file like this:

echo "main(){int i; i=i+1;}" >> main.c

gcc main.c -o main

Is there any way to convert main binary file to a windows exe file?

peterh
  • 11,875
  • 18
  • 85
  • 108
sMojtaba Mar
  • 359
  • 2
  • 5
  • 15
  • 1
    Although technically possible, would be insanely complicated, headers change, change all dynamically linked libraries etc. What are your requirements? – Adam Jan 18 '13 at 09:48
  • 1
    thanks alot, i know that it is not too easy, but assume we have a simple binary file like "main" as i mentioned above how can i convert it to a windows exe file? – sMojtaba Mar Jan 18 '13 at 10:06
  • @Mojtaba In your place I looked for a runtime binary emulator, and tried to link it statically with the linux binary. It will be slow and dirty, but this is how you can get what you wanted with the smallest possible development effort. – peterh Nov 27 '14 at 16:04

4 Answers4

2

You can not convert a linux executeable into a windows executeable. But you can compile the source with cross-compiler.

E.g: MinGw32

if you are in ubuntu:

sudo apt-get install mingw32
i586-mingw32msvc-cc main.c -o main.exe
lmcanavals
  • 2,339
  • 1
  • 24
  • 35
mstrewe
  • 441
  • 3
  • 15
  • thanks alot i know tha it is not too easy but assume we have a simple binary file like "main" as i mention a bove how can i convert tis to an exe file – sMojtaba Mar Jan 18 '13 at 10:02
  • 1
    If you only have an linux executable file and no chance to access the source code of that binary you can only use cygwin in windows to execute the program. A conversion is not possible due to the compiler binds the systemcalls (like consoleoutput) to the system in which the program was compiled. in your case the program was compiled in linux so the mashinecode calls the linux systemcalls. you have no chance to convert it to a windows exe – mstrewe Jan 18 '13 at 10:07
  • Cygwin emulates a linux enviroment on the windows mashine, it does not convert the binary. Cygwin starts the binary in a sandbox so that the program can find the needed libraries and "endpoints" for the system calls. – mstrewe Jan 18 '13 at 12:06
  • If you had some incredibly simple program (such as 'int main() { return 0; }'), would that be feasible to port just from the binary? – Kevin Feb 08 '15 at 18:59
  • @Kevin No, Direct conversation is not possible. Maybe you can try to decompile the excecutable in the source language and recompile it on you target platform. I do not know if this works. – mstrewe Feb 11 '15 at 14:32
1

There are no means to convert the binary.

Regular ways to go are:

  • Recompile for other platform, but this requires the source (and cross-platform support in the source or the used libraries must be available on the other platform as well). cygwin/mingw, for example, can help providing the required support/libraries.

  • wine could be used to run Windows binaries on Linux (but not the other way around)

Veger
  • 37,240
  • 11
  • 105
  • 116
  • thanks alot really i know it is not too easy to this convertion; – sMojtaba Mar Jan 18 '13 at 10:01
  • @veger Cygwin cannot run Linux binaries -- see its [home page](http://cygwin.com): "Cygwin is not: a way to run native Linux apps on Windows. You must rebuild your application from source if you want it to run on Windows." – P. B. Mar 04 '17 at 01:34
  • @PengBai You are totally right, I updated the answer. – Veger Mar 04 '17 at 14:42
1

If you have the lastest windows 10. Just install linux subsystem in the appstore. you can run whatever linux binary in windows you want

user251335
  • 11
  • 1
1

If you need to run your code/app/program in linux/mac/windows under another OS (linux to win or reverse exc..) but you don't want to use virtual machines or wsl systems you can use docker. Here is link: https://www.docker.com But you will need to learn first. What Is Docker? Docker is similar in concept to Virtual Machines, except it’s much more lightweight. Instead of running an entire separate operating system (which is a massive overhead), Docker runs containers, which use the same host operating system, and only virtualize at a software level

BARIS KURT
  • 477
  • 4
  • 15