如何通过 Windows 命令提示符编译 C/C++ 程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6281493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I compile a C/C++ program through windows command prompt?
提问by Bap Johnston
Im new to the C/C++ programming language an so far have used the Code::blocks program for writing and compiling programs. However I need to know how to compile a program via windows command prompt as I need to access the assembly code created. My compilers are mingw32-gcc.exe, mingw32-g++.exe
我是 C/C++ 编程语言的新手,到目前为止已经使用 Code::blocks 程序编写和编译程序。但是,我需要知道如何通过 windows 命令提示符编译程序,因为我需要访问创建的汇编代码。我的编译器是 mingw32-gcc.exe、mingw32-g++.exe
回答by
Please read Compile Programs with MinGW -- A Guide for New Users.
To make gcc
produce assembler code, use -S
option:
请阅读使用 MinGW 编译程序 - 新用户指南。要gcc
生成汇编代码,请使用-S
选项:
-S Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s. Input files that don't require compilation are ignored.
-S Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s. Input files that don't require compilation are ignored.
Good luck!
祝你好运!
回答by Sahil Khaneja
if you have codeblocks installed with mingw as the gcc compiler then follow these steps
如果您使用 mingw 作为 gcc 编译器安装了代码块,请按照以下步骤操作
- Right click on my computer -> go to properties -> advance system settings
- Then make an environment variable named PATHand paste the complete url like program file (x86)/codeblocks/mingw/bin.
- now open cmd
- go to the directory where your program is saved.
- type gcc program_name.c -o program_name.exe to compile the program.
- run the program by typing program_name
- 右键单击我的电脑-> 转到属性-> 高级系统设置
- 然后创建一个名为PATH的环境变量并粘贴完整的 url,如程序文件 (x86)/codeblocks/mingw/bin。
- 现在打开cmd
- 转到保存程序的目录。
- 输入 gcc program_name.c -o program_name.exe 编译程序。
- 通过键入 program_name 运行程序