如何使用命令行中的cc命令编译C程序

huangapple go评论63阅读模式
英文:

How to compile C programs using cc command in cmd

问题

我想知道如何在命令行中(我在Windows上)使用cc编译器/汇编器来编译/汇编C程序。

我尝试在已安装MinGW和MSYS2的情况下,使用cc命令运行一个.c文件,但未成功。

英文:

I'd like to know how I can use cc compiler/assembler from cmd (I am on windows) to compile/assemble C programs.

I tried running the cc command on a .c file with MinGW and MSYS2 installed, and it did not work.

答案1

得分: 2

一个简单的方法是从 https://winlibs.com/ 获取 Windows 的 MinGW-w64 独立构建版本。

这将提供您编译和链接 Windows 程序所需的所有工具。

命令将是 gcc 而不是 cc,但要运行它,您应该指定完整的路径。下载后,您可以在 mingw64\bin\gcc.exe 下找到它。或者您可以将其添加到 PATH 环境变量中(但我不建议这样做)。

https://winlibs.com/ 上有如何使用它的示例。

如果您是初学者,建议使用像VSCode或Code::Blocks这样的GUI,这样您就不需要使用命令行操作来编译和链接您的代码,甚至可以在需要时调试您的代码。

英文:

One easy way to do this is to get a standalone build of MinGW-w64 for Windows from https://winlibs.com/.

This will provide you with all the tools you need to compile and link Windows programs.

The command will be gcc instead of cc, but to run it, you should specify its complete path. When the download is extracted you can find it under mingw64\bin\gcc.exe. Or you can add it to the PATH environment variable (but I don't recommend this).

There are examples on how to use it at https://winlibs.com/.

If you are a beginner it is recommended to use a GUI like VSCode or Code::Blocks, so you won't need command line actions to compile and link your code, and you can even debug your code if you need to.

huangapple
  • 本文由 发表于 2023年5月7日 12:55:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192251.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定