在Windows上运行的CentOS上运行C程序

时间:2015-03-12 19:17:41

标签: c linux windows centos cross-compiling

我想编写一个能够在Windows和CentOS机器之间通过网络进行通信的程序。

现在,我的问题是我无法访问centOS(6/7 x64)机器来完成/测试它。有没有办法在Windows机器上构建它,以便它也可以在centOS上兼容?它将具有非常简单的命令行界面,因此不需要GUI兼容性。

3 个答案:

答案 0 :(得分:1)

如果您的意思是在Windows上编译文件,然后在Centos上运行可执行文件,则答案为no(见下文)。

如果你想在Windows上编写可以移动到Centos框的代码,编译并运行,那么答案是肯定的。为此,您需要确保编写至少符合posix标准的代码。请注意,如果您需要图形界面(如QT),则有许多跨平台框架。

N.B。 - 如果您希望能够将可执行文件从Windows框移动到Linux框,则应该可以进行交叉编译。您可能(可能)需要在Windows上编译时使用gcc(mingw)。

答案 1 :(得分:1)

我的ELLCC交叉编译工具链可以在Windows和Linux主机上编译针对Linux和Windows系统的C和C ++程序。预构建的二进制包可供下载。

它非常易于使用。以下是在Linux主机上为Linux和Windows构建hello world程序的示例:

[~/ellcc/examples/hello] dev% ~/ellcc/bin/ecc -target x86_64-linux-eng main.c 
[~/ellcc/examples/hello] dev% ./a.out 
hello world
[~/ellcc/examples/hello] dev% ~/ellcc/bin/ecc -target x86_64-w64-mingw32 main.c
[~/ellcc/examples/hello] dev% ./a.exe 
fixme:winediag:start_process Wine Staging is a testing version containing experimental patches.
fixme:winediag:start_process Please report bugs at http://bugs.wine-staging.com (instead of winehq.org).
hello world

和Windows系统上的相同程序:

C:\ellcc\examples\hello>c:\ellcc\bin\ecc -target x86_64-w64-mingw32 main.c
C:\ellcc\examples\hello>.\a.exe
hello world
C:\ellcc\examples\hello>C:\ellcc\examples\hello>c:\ellcc\bin\ecc -target x86_64-w64-mingw32 main.c
C:\ellcc\examples\hello>.\a.exe
hello world
C:\ellcc\examples\hello>

ELLCC面向各种Linux系统,包括ARM,Mips,PowerPC和X86系统以及32位和64位Windows系统。

答案 2 :(得分:0)

最佳解决方案可能是在VirtualBox等虚拟机上安装CentOS,并将其用于测试和开发。

相关问题