[英]Why does my Linux-compiled binary not work when I run it on Windows?
I have a really easy code using C++ with Gtkmm :我有一个使用 C++ 和 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.我在 Linux 上编译它,我可以执行它是完美的。 But the problem is when I copy past the executable I don't achieve to make workable on Windows.
但问题是当我复制过去的可执行文件时,我无法在 Windows 上运行。 But I always think Gtkmm is portable ?!
但我一直认为 Gtkmm 是便携的?!
How can I solve this problem ?我该如何解决这个问题?
Thank you very much !非常感谢!
Gtkmm is indeed a portable implementation. Gtkmm 确实是一个可移植的实现。 Nevertheless you cannot simply copy and paste an executable from Linux to Windows.
然而,您不能简单地将可执行文件从 Linux 复制并粘贴到 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.在您的情况下,您必须为 Windows 创建典型的
.exe
可执行文件。
If you want to cross-compile the executable for Windows (ie use your Linux machine to create the .exe
file for Windows), have a look at the mingw
compiler toolchain.如果您想为 Windows 交叉编译可执行文件(即使用您的 Linux 机器为 Windows 创建
.exe
文件),请查看mingw
编译器工具链。 This blog might also have some interesting information for you.这个博客可能也有一些有趣的信息给你。
It is because executables on Linux and Windows have different structures:这是因为 Linux 和 Windows 上的可执行文件具有不同的结构:
On Linux, you have ELF binaries, which do not work on Windows.在 Linux 上,您有 ELF 二进制文件,它们在 Windows 上不起作用。 Similarly, if you take an EXE binary from Windows and try to execute it on a Linux machine, it will not work.
同样,如果您从 Windows 获取一个 EXE 二进制文件并尝试在 Linux 机器上执行它,它也不会工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.