0

given some pure machine language commands, for example the following bytes:

1011100010011010000000100000000000000000
11000011

(taken from: How to write and execute PURE machine code manually without containers like EXE or ELF?)? I understand that in general there needs to be a .EXE, ELF, or .OUT wrapper, but as far as I know these formats are platform-specific just to be able to double-click and run them.

Does there exist a file format that can be double-clicked across windows, linux, and mac, and run the same machine code (assuming no external dependencies) ?

  • Not that I know without installing something. Linux + Mac probably will work together in something like bash, but not Windows – afghanimah Apr 27 '20 at 17:05
  • @afghanimah hmm interesting so theres nothing that can be double clicked (or even just run in the terminal) across all 3, natively? how does unity's cross-platform game build work? – B''H Bi'ezras -- Boruch Hashem Apr 27 '20 at 17:09
  • Unity uses C#, so it uses C#'s mechanism for cross-platform (which is .net byte code), plus some custom code for the various operating systems, i'm sure. – Erik Eidt Apr 27 '20 at 19:16
  • @ErikEidt what do you mean though, surely C# compiles to machine language? But even so the actual same program can be double clicked on any platform, how does that work? – B''H Bi'ezras -- Boruch Hashem Apr 27 '20 at 19:42
  • @bluejayke Unity is just C# with some Unity libraries which compiles to IL which is interpreted by .NET or Mono Runtime by using a JIT compiler to convert IL to machine code for the machine you're using. – afghanimah Apr 27 '20 at 20:14
  • @afghanimah Oh its only converted for the machine you're using? I thought the "windows, linux and mac standalone" worked for all 3 at once? – B''H Bi'ezras -- Boruch Hashem Apr 28 '20 at 07:02
  • You download a different version for each, for example: windows is running Unity.exe and mac is running Unity.app – afghanimah Apr 28 '20 at 18:51
  • @afghanimah by Unity do you mean the unity editor or the application compiled by the unity editor – B''H Bi'ezras -- Boruch Hashem Apr 29 '20 at 05:08
  • @bluejayke The Unity Editor is different for each platform, and you need to set a target platform in the editor to build for that platform, so both – afghanimah Apr 29 '20 at 05:12
  • @afghanimah oh so even when you build and select the option "standalone for windows, linux and mac" what it really means is "standalone for windows OR linux OR mac, depending on what editing you have installed"? So it's not just a one-build-for-all platforms, there are three separate builds? – B''H Bi'ezras -- Boruch Hashem Apr 29 '20 at 05:14
  • @bluejayke correct; it can almost be thought of as "desktop". In fact, if you click on that, you'll see you have a drop-down for exactly which platform to target. I believe you can install the different build supports for other platforms, but they are still all separate builds: Mac cannot run a Windows build, Windows can't run a Linux build, Linux cannot run a Mac build, etc. – afghanimah Apr 29 '20 at 05:21
  • @afghanimah oh wow I guess I did not realize that when exporting unity games (I guess it was never tested on another platform..) so the only way to make code "work" across all platforms is basically have it compile down individually to each platform? and even though the machine code could theoretically be the same for the same processors, but there's no possible way to run the same exact file type across all platforms (as of now)? – B''H Bi'ezras -- Boruch Hashem Apr 29 '20 at 05:24
  • @bluejayke yes, you would need to build and distribute the different versions. The code is mostly the same, there are just differences between platforms, like OS-level stuff is different. Also, this conversation is getting long, so move to a chat if you like – afghanimah Apr 29 '20 at 05:29
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/212752/discussion-between-bluejayke-and-afghanimah). – B''H Bi'ezras -- Boruch Hashem Apr 29 '20 at 05:31

1 Answers1

2

Does there exist a file format that can be double-clicked across windows, linux, and mac, and run the same machine code (assuming no external dependencies) ?

The short answer is no.

The longer answer is that you are mixing concepts and levels of abstractions: double-click is not an OS-level concept, and no OS runs a binary in response to double-click.

They all run a binary in response to execve or a CreateProcess system call, and there is no universal file format that will be acceptable to the OS on all of Linux, Mac OS and Windows.

how does unity's "windows, mac and linux standalone" game build work

In the same way a Python foo.py file works on all platforms: there is a native binary which interprets the code contained in the game. The native binary has different file format on each platform (ELF on Linux, Mach-O on Mac, PE on Windows).

Employed Russian
  • 199,314
  • 34
  • 295
  • 362