gcc
GNU Compiler Collection의 컴파일러 드라이버. 전처리, 컴파일, 어셈블, 링크 단계를 옵션에 따라 제어한다.
Summary
- C 소스 컴파일과 링크를 한 번에 처리할 때 기본 진입점으로 자주 사용한다.
- `gcc`는 드라이버이므로 내부적으로 `cc1`, `as`, `ld` 같은 하위 도구를 호출한다.
- CPP 소스를 다룰 때는 링크 단계에서 표준 CPP 라이브러리 처리가 필요한 경우가 많으므로 CPP 전용 드라이버 사용 여부를 함께 검토한다.
Usage
gcc [options] file...
gcc [options…] file…
Options
-E: 전처리만 수행하고 컴파일하지 않는다.-S: 컴파일만 수행하고 어셈블/링크하지 않는다.-c: 오브젝트 파일까지만 만들고 링크하지 않는다.-o FILE: 출력 파일 이름을 지정한다.-I DIR: 헤더 검색 경로를 추가한다.-L DIR: 라이브러리 검색 경로를 추가한다.-l NAME: `libNAME` 형식의 라이브러리를 링크한다.-Wall: 자주 필요한 경고를 활성화한다.-Wextra: 추가 경고를 활성화한다.-g: 디버깅 심볼을 포함한다.-O0,-O2,-O3: 최적화 수준을 지정한다.-std=STANDARD: 언어 표준을 지정한다.-v: 실제 호출되는 하위 프로그램과 검색 경로를 표시한다.-###: 실행하지 않고 어떤 명령이 호출될지 인용 형태로 출력한다.
Examples
gcc hello.c -o hello gcc -Wall -Wextra -O2 hello.c -o hello gcc -c hello.c -o hello.o gcc -E hello.c -o hello.i gcc -S hello.c -o hello.s gcc main.c util.c -lm -o app
`gcc`는 CPP 소스도 처리할 수 있지만, 링크 단계에서 CPP 표준 라이브러리를 자동으로 기대하는 작업은 CPP 전용 드라이버 기준으로 점검하는 편이 안전하다.
Installation
sudo apt-get install build-essential
Help
Usage: gcc [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 cpp 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. In order to pass
other options on to these processes the -W<letter> options must be used.
Compatibility
- 이 작업 환경에서 확인한 버전은 `gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-28)` 이다.
- 배포판과 툴체인 조합에 따라 기본 표준, 기본 include 경로, 링크 동작은 달라질 수 있다.
See Also
History
- codex:: 2026-06-17 Reorganized the gcc page into a structured CLI reference with options, examples, and help output.
- codex:: 2026-06-17 Replaced CPP-related terminology and removed plus-sign based notation from this page.