简体   繁体   中英

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.

Now, my problem is that I do not have access to a centOS (6/7 x64) machine to have it done / tested. Is there a way of building it on a Windows machine so that it will be compatible on centOS too? It is going to have a very simple command line interface so there's no need for a GUI compatibility.

If you mean to compile a file on Windows and then have the executable run on Centos then the answer no (see below).

If you mean to write code on Windows that you can move to a Centos box, compile and run, then the answer is yes. To do this you need to insure that you write code that is at least posix compliant. Note that there are a number of cross-platform frameworks if you want graphical interfaces (like 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. You will (probably) need to use gcc (mingw) as you compiler on Windows.

My ELLCC cross compilation tool chain can compile C and C++ programs targeting Linux and Windows systems on both Windows and Linux hosts. 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:

[~/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:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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