[英]Cross-Compiling C and C++ application in Windows 7, using MinGW under linux
I have installed MinGW compiler in Windows 7. GCC version is 4.6.1. 我已经在Windows 7中安装了MinGW编译器。GCC版本为4.6.1。
I have Hello World application: 我有Hello World应用程序:
#include <stdio.h>
int main( int argc, char* argv[] )
{
printf( "Hello World!" );
return 0;
}
How I can compile this application under Windows 7, using MinGW compiler, in order that i can run this application in linux, without recompile. 我如何使用MinGW编译器在Windows 7下编译此应用程序,以便可以在Linux中运行该应用程序而无需重新编译。
I don't think MinGW provides any cross-compilers that are able to produce linux binaries. 我认为MinGW不提供任何能够生成linux二进制文件的交叉编译器。
This can be done using Cygwin, they provide cross-compilers so that you can compile linux binaries on a Windows host. 这可以使用Cygwin完成,Cygwin提供了交叉编译器,因此您可以在Windows主机上编译linux二进制文件。 You just need to install the necessary packages. 您只需要安装必要的软件包。
You need to distinguish two systems here: The build system, which is the one your compiler runs on, and the host system, which is the one your executable will run on. 您需要在此处区分两个系统: 构建系统,即您的编译器在其上运行的系统;以及主机系统,即您的可执行文件将在其上运行的系统。 MinGW is the GCC compiler for the host system Windows. MinGW是主机系统Windows的GCC编译器。 So, you can compile on Windows for Windows or cross-compile on Linux for Windows. 因此,您可以在Windows的Windows上编译或在Linux的Windows上交叉编译。 You are looking for a cross compiler for build Windows to host linux, which might be included in Cygwin. 您正在寻找用于构建Windows的交叉编译器来承载linux,Cygwin中可能包含该交叉编译器。
However, generally such things are not well-supported, since Windows is normally used as an end-user only system, not for developing, and UNIX systems for developers. 但是,由于Windows通常仅用于最终用户系统(而不是用于开发),而UNIX系统通常用于开发人员,因此通常情况下,这种情况并不能得到很好的支持。 So, you are compiling against the stream here, something not too many people do. 因此,您在这里针对流进行编译,这不是太多人做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.