1

I have Windows 10 with the Ubuntu userspace based on Windows Linux Subsystem, with the gcc package installed. Using gcc -static, I built a statically linked binary, hello, that the usual utilities describe as follows:

$ ldd hello
        not a dynamic executable

$ file hello
hello: ELF 64-bit LSB  executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.24, BuildID[sha1]=xxx, not stripped

If I take this executable to a random Windows system that doesn't have the Linux-supporting subsystem installed, will it still run?

Phil Miller
  • 36,389
  • 13
  • 67
  • 90
  • [This question](http://stackoverflow.com/questions/38786014/how-to-compile-executable-for-windows-with-gcc-with-linux-subsystem) suggests not – Phil Miller Feb 07 '17 at 01:48

1 Answers1

2

No. It requires WSL to map Linux Kernel calls to Windows. Second it needs bash to load it since it's an ELF executable not a Windows one.

Yttrill
  • 4,725
  • 1
  • 20
  • 29
  • It needs bash to load it, specifically? That would be an unusual modification of stock bash code, which would just call `exec()` on the path to the requested command. I assume any program running under WSL could do just as well. – Phil Miller May 03 '17 at 19:50
  • bash.exe is a windows program that activates Windows subsystem for Linux and does some other stuff like open a Windows console. At present if you kill that process all the Linux process it spawned directly or indirectly are also killed, so yes, the *Windows* bash.exe is not the same as the bash in Ubuntu. To put it another way you can't call Linux exec() until *after* WSL Linux kernel calls are activated. – Yttrill May 04 '17 at 23:58
  • In particular, WSL is just code that translates kernel calls from Linux to Windows, but it cannot work unless a suitable environment is established. In Linux this is done by bootstrapping your computer (switching it on). So bash.exe windows program has to somehow emulate bootup by creating an environment. For example, mounting Windows C: drive as /mnt/c/, setting up /proc, etc etc. – Yttrill May 05 '17 at 00:03