简体   繁体   English

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

[英]Run C program on CentOS written in Windows

I want to write a program which should be able to communicate over a network between Windows and CentOS machines. 我想编写一个程序,该程序应该能够在Windows和CentOS计算机之间通过网络进行通信。

Now, my problem is that I do not have access to a centOS (6/7 x64) machine to have it done / tested. 现在,我的问题是我无法访问centOS(6/7 x64)计算机来完成/测试。 Is there a way of building it on a Windows machine so that it will be compatible on centOS too? 是否可以在Windows机器上构建它,使其也与centOS兼容? It is going to have a very simple command line interface so there's no need for a GUI compatibility. 它将具有非常简单的命令行界面,因此不需要GUI兼容性。

If you mean to compile a file on Windows and then have the executable run on Centos then the answer no (see below). 如果您打算在Windows上编译文件,然后在Centos上运行可执行文件,则答案为否(请参阅下文)。

If you mean to write code on Windows that you can move to a Centos box, compile and run, then the answer is yes. 如果您打算在Windows上编写可移至Centos框,进行编译并运行的代码,那么答案是肯定的。 To do this you need to insure that you write code that is at least posix compliant. 为此,您需要确保编写的代码至少与posix兼容。 Note that there are a number of cross-platform frameworks if you want graphical interfaces (like QT). 请注意,如果需要图形界面(例如QT),则有许多跨平台框架。

NB -- It should be possible to cross-compile if you want to be able to move the executable from a windows box to a Linux box. 注意:如果您希望能够将可执行文件从Windows盒移动到Linux盒,则应该可以交叉编译。 You will (probably) need to use gcc (mingw) as you compiler on Windows. 在Windows上编译时,您可能需要使用gcc(mingw)。

My ELLCC cross compilation tool chain can compile C and C++ programs targeting Linux and Windows systems on both Windows and Linux hosts. 我的ELLCC交叉编译工具链可以在Windows和Linux主机上编译针对Linux和Windows系统的C和C ++程序。 Pre-built binary packages are available for download. 预构建的二进制程序包可供下载。

It's pretty easy to use. 它很容易使用。 Here is an example of building a hello world program for Linux and Windows on a Linux host: 这是在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

and the same program on a Windows system: 和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 targets a variety of Linux systems including ARM, Mips, PowerPC and X86 systems as well as 32 and 64 bit Windows systems. ELLCC针对各种Linux系统,包括ARM,Mips,PowerPC和X86系统以及32位和64位Windows系统。

最好的解决方案可能是在虚拟机(例如VirtualBox)上安装CentOS并将其用于测试和开发。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM