如何在Linux中编译C代码以在Windows上运行? [英] How to compile C code in Linux to run on Windows?

查看:54
本文介绍了如何在Linux中编译C代码以在Windows上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Linux/GNU GCC to compile C source code. Is there any way I can generate .exe files for Windows running on x86 or x64 architecture? The compiled code needs to be generated on the Linux machine.

推荐答案

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

You would need a cross-compiler to create a Windows executable in Linux.

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

Mingw-w64 is an advancement of the original mingw.org project, created to support the GCC compiler on Windows systems.

安装交叉编译

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

这篇关于如何在Linux中编译C代码以在Windows上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆