GCC
GCC
Windows平台
Cygwin 和 MinGW 都是 Windows 平台上常用的开发工具,可以在 Windows 上编译和运行 Unix/Linux 平台上的 C/C++ 程序。
Cygwin 是一个运行在 Windows 上的类 Unix 环境,它提供了大量的 Unix/Linux 命令和工具,包括 GCC 编译器、Make 工具、Bash shell 等。Cygwin 在 Windows 上运行时会模拟 Unix/Linux 环境,所以它的性能和稳定性比较好。但是,Cygwin 的安装包比较大,需要下载几百兆的文件,安装和配置也比较麻烦。
MinGW 是一个 Windows 平台上的开发工具集,它包括 GCC 编译器、Make 工具等工具,可以编译和运行 Unix/Linux 平台上的 C/C++ 程序。与 Cygwin 不同,MinGW 不需要模拟 Unix/Linux 环境,它直接在 Windows 上运行,因此性能比较好。此外,MinGW 的安装包比较小,下载和安装也比较简单。
总的来说,Cygwin 更加完整和强大,可以提供更多的 Unix/Linux 工具和命令,但是安装和配置比较麻烦,而且性能和稳定性可能不如 MinGW。MinGW 更加简单和易于使用,适合开发小型项目和快速原型开发。具体选择哪个工具取决于您的项目需求和个人偏好。
GCC参数
预处理器:将.c 文件转化成 .i 文件,使用的 gcc 命令是:gcc –E,对应于预处理命令 cpp;
编译器:将.c/.h 文件转换成.s 文件,使用的 gcc 命令是:gcc –S,对应于编译命令 cc –S;
汇编器:将.s 文件转化成 .o 文件,使用的 gcc 命令是:gcc –c,对应于汇编命令是 as;
链接器:将.o 文件转化成可执行程序,使用的 gcc 命令是: gcc,对应于链接命令是 ld;
加载器:将可执行程序加载到内存并进行执行,loader 和 ld-linux.so。
# -c 预处理、编译、汇编 生成 .o文件
gcc -c main.c
-> main.o
# -S 预处理、编译 .s文件
gcc -S main.c
# -E 只激活预处理,这个不生成文件, 你需要把它重定向到一个输出文件里面
gcc -E .\main.c >hello.txt
# -o 制定目标名称, 默认的时候, gcc 编译出来的文件是 a.out a.exe
gcc -o main.exe main.c
gcc --help
Usage: gcc.exe [options] file...
Options:
-pass-exit-codes Exit with highest error code from a phase.
--help Display this information.
--target-help Display target specific command line options.
--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].
Display specific types of command line options.
(Use '-v --help' to display command line options of sub-processes).
--version Display compiler version information.
-dumpspecs Display all of the built in spec strings.
-dumpversion Display the version of the compiler.
-dumpmachine Display the compiler's target processor.
-print-search-dirs Display the directories in the compiler's search path.
-print-libgcc-file-name Display the name of the compiler's companion library.
-print-file-name=<lib> Display the full path to library <lib>.
-print-prog-name=<prog> Display the full path to compiler component <prog>.
-print-multiarch Display the target's normalized GNU triplet, used as
a component in the library path.
-print-multi-directory Display the root directory for versions of libgcc.
-print-multi-lib Display the mapping between command line options and
multiple library search directories.
-print-multi-os-directory Display the relative path to OS libraries.
-print-sysroot Display the target libraries directory.
-print-sysroot-headers-suffix Display the sysroot suffix used to find headers.
-Wa,<options> Pass comma-separated <options> on to the assembler.
-Wp,<options> Pass comma-separated <options> on to the preprocessor.
-Wl,<options> Pass comma-separated <options> on to the linker.
-Xassembler <arg> Pass <arg> on to the assembler.
-Xpreprocessor <arg> Pass <arg> on to the preprocessor.
-Xlinker <arg> Pass <arg> on to the linker.
-save-temps Do not delete intermediate files.
-save-temps=<arg> Do not delete intermediate files.
-no-canonical-prefixes Do not canonicalize paths when building relative
prefixes to other gcc components.
-pipe Use pipes rather than intermediate files.
-time Time the execution of each subprocess.
-specs=<file> Override built-in specs with the contents of <file>.
-std=<standard> Assume that the input sources are for <standard>.
--sysroot=<directory> Use <directory> as the root directory for headers
and libraries.
-B <directory> Add <directory> to the compiler's search paths.
-v Display the programs invoked by the compiler.
-### Like -v but options quoted and commands not executed.
-E Preprocess only; do not compile, assemble or link.
-S Compile only; do not assemble or link.
-c Compile and assemble, but do not link.
-o <file> Place the output into <file>.
-pie Create a dynamically linked position independent
executable.
-shared Create a shared library.
-x <language> Specify the language of the following input files.
Permissible languages include: c c++ assembler none
'none' means revert to the default behavior of
guessing the language based on the file's extension.
Options starting with -g, -f, -m, -O, -W, or --param are automatically
passed on to the various sub-processes invoked by gcc.exe. In order to pass
other options on to these processes the -W<letter> options must be used.
For bug reporting instructions, please see:
<https://sourceforge.net/projects/mingw-w64>.