简体   繁体   English

为什么我的 Linux 编译的二进制文件在 Windows 上运行时不起作用?

[英]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 机器上执行它,它也不会工作。

See ELF and EXE for more information.有关详细信息,请参阅ELF和 EXE。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的二进制文件可以在Windows 8上运行而不能在Windows 7上运行? - Why does my binary run on Windows 8 but not on Windows 7? 为什么我的代码在运行时保持循环 - why does my code stay in a loop when i run it 重定向标准输出时,为什么我的程序运行得更快? - Why does my program run faster when I redirect stdout? 来自 Windows 的字符串函数在 Ubuntu(Linux Mint)上通过 g++ 编译时,Visual Studio 似乎不起作用 - String functions from Windows Visual Studio seem to not work when compiled through g++ on Ubuntu(Linux Mint) 为什么标头文件在Windows中有效,但在Mac&Linux上却无效? (strrev) - Why does a header file work in Windows but not on Mac & Linux? (strrev) 如何在Windows中运行最初为Linux编写的已编译C ++代码? - How to run a compiled C++ code written originally for Linux in Windows? 为什么我的修剪二叉树的递归解决方案不起作用? - Why does my recursive solution to pruning binary tree not work? 为什么我的文件/目录操作在 Windows 上可以正常工作,但在 Linux 上却不能? - Why does my file/dir manipulation works fine on Windows but not on Linux? 为什么我的输出流seg错误并且我的虚拟析构函数不起作用,但是当我杀死虚拟机时却可以 - Why is my output stream seg faulting and my virtual destructor does not work but when i kill virtual it does 为什么这种二进制转换不起作用? - why this binary conversion does not work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM