c - 如何在 Linux 中编译 C 代码以在 Windows 上运行?

标签 c linux windows

<分区>

我正在使用 Linux/GNU GCC 编译 C 源代码。有什么方法可以为在 x86 或 x64 架构上运行的 Windows 生成 .exe 文件?需要在Linux机器上生成编译后的代码。

最佳答案

您需要交叉编译器才能在 Linux 中创建 Windows 可执行文件。

Mingw-w64 是对原始 mingw.org 项目的改进,旨在支持 Windows 系统上的 GCC 编译器。

安装交叉编译

sudo apt-get install mingw-w64

32位

i686-w64-mingw32-gcc -o test.exe test.c

64位

x86_64-w64-mingw32-gcc -o test.exe test.c

关于c - 如何在 Linux 中编译 C 代码以在 Windows 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44670209/

相关文章:

windows - Windows 的 100 纳秒时间单位是否有标准术语?

c - 使用gets函数输入

php - PHP输出和C输出与相同的代码不匹配

c - 找到矩阵中等于坐标 (i+j) 之和的所有元素

c - 当我想将数组写入文件时内存损坏

c++ - Eclipse 不解析 gcc 输出

windows - 为什么在 Git 配置中忽略任何引号?

c - 链接器错误 :/usr/bin/ld: cannot find -lc

linux - name.d/(例如/etc/httpd/conf.d)目录有名称吗?

windows - 使用 "SupressWhenMinimzed"安全关闭 RDP session 后,远程计算机的屏幕分辨率发生变化