【问题标题】:Run C program on CentOS written in Windows在 CentOS 上运行 Windows 编写的 C 程序
【发布时间】:2015-05-15 02:53:26
【问题描述】:

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

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

【问题讨论】:

  • 您可以使用 Amazon AWS / Elastic Cloud 之类的工具来执行此操作,但对于单个程序来说可能太多了。
  • 这个问题似乎属于 Stack Exchange 网络中的另一个站点,因为它与编程或开发无关。也许你应该试试Software Recommendations Stack Exchange。您应该询问有关虚拟机软件或模拟器软件的信息。请务必详细说明您的要求。
  • cross compiling 从 Windows 到 CentOS 可以提供帮助,但这并不容易

标签: c linux windows centos cross-compiling


【解决方案1】:

如果您的意思是在 Windows 上编译一个文件,然后让可执行文件在 Centos 上运行,那么答案是否定的(见下文)。

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

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

【讨论】:

    【解决方案2】:

    我的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 系统。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 我不能。我试图在 VirtualBox 上安装 centOS,但没有成功。此外,由于我的笔记本电脑问题,我什至无法将 centOS 作为第二个操作系统安装。此外,我只在 2GB RAM 机器 2.2Ghz 上运行,所以即使我能够这样做(在 VM 上运行),我的笔记本电脑也会运行缓慢。
      • @Alexander 你用 GUI 安装了吗?如果是这样,也许你可以放弃它。纯 cli 可以加速很多。
      猜你喜欢
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 2015-04-14
      • 2021-01-18
      • 1970-01-01
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多