我几乎可以肯定我的问题是因为编译的程序被编译为linux可执行文件,但我只是想仔细检查一下.
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
上面的"程序"应该在Windows和Linux上编译得很好,因为它与源代码兼容,因为没有特定于操作系统的库或类似的东西.
然而,当我在我的Linux机器上键入"c99 hello.c -o hello.exe",然后将该"可执行文件"传输到Windows机器时,它拒绝运行.根据我的理解,Linux生成一个只能在linux上运行的可执行文件,因此添加".exe"无效.要在Linux for Windows上构建该程序,我需要在Windows机器上重新编译该程序吗?或者还有另一种更简单的方法吗?