Why does my Linux-compiled binary not work when I run it on Windows?

Viewed 198

I have a really easy code using C++ with Gtkmm :

#include <gtkmm.h>

int main(int argc, char *argv[]){
Gtk::Main app(argc, argv);
Gtk::Window window;
Gtk::Main::run(window);
return EXIT_SUCCESS;
}

I compile this on Linux and It is perfect I can execute it. But the problem is when I copy past the executable I don't achieve to make workable on Windows. But I always think Gtkmm is portable ?!

How can I solve this problem ?

Thank you very much !

2 Answers

Gtkmm is indeed a portable implementation. Nevertheless you cannot simply copy and paste an executable from Linux to Windows. You have to compile your program once for each platform you're running it on. In your case, you have to create the typical .exe executable for Windows.

If you want to cross-compile the executable for Windows (i.e. use your Linux machine to create the .exe file for Windows), have a look at the mingw compiler toolchain. This blog might also have some interesting information for you.

It is because executables on Linux and Windows have different structures:
On Linux, you have ELF binaries, which do not work on Windows. Similarly, if you take an EXE binary from Windows and try to execute it on a Linux machine, it will not work.

See ELF and EXE for more information.

Related