0

I just compiled a simple "Hello World!" program on Linux. For reference, here it is:

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}

This program runs perfectly on Linux. The same code compiled on Windows can be run on Windows as well, but I can't seem to compile it on Linux with g++ myprog.cpp -o prog.exe and then run it on Windows.

Shouldn't the machine code should be the same on Linux and Windows, because the program is the same?

Telescope
  • 2,068
  • 1
  • 5
  • 22
Ethan Brown
  • 11
  • 1
  • 2
  • 3
    The two platforms use different formats for their executables. – Paul Sanders Jul 05 '20 at 20:18
  • 3
    The machine code is not the same because the two use different [calling conventions](https://en.wikipedia.org/wiki/X86_calling_conventions). Also, the executable file formats are completely different (ELF vs PE). – Nate Eldredge Jul 05 '20 at 20:18
  • 3
    I/O is possibly the most platform-specific part of the standard library. – molbdnilo Jul 05 '20 at 20:21
  • 1
    Have you looked at the compiled code and compared them? It's very unlikely that they are exactly the same. –  Jul 05 '20 at 20:59
  • Possible duplicate: https://stackoverflow.com/questions/38786014/how-to-compile-executable-for-windows-with-gcc-with-linux-subsystem – Jerry Jeremiah Jul 06 '20 at 05:33

0 Answers0