gcc
Master GCC flag selection for debug and release builds, from optimization levels and warning discipline to link-time optimization and profile-guided optimization. Covers common compilation errors, sanitizer instrumentation, and integration with GNU Make and CMake.
GCC helps you select compiler flags for debug and release builds, optimization levels, and troubleshoot compilation errors.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-06-27
GCC helps you select compiler flags for debug and release builds, optimization levels, and troubleshoot compilation errors. Master GCC flag selection for debug and release builds, from optimization levels and warning discipline to link-time optimization and profile-guided optimization. Covers common compilation errors, sanitizer instrumentation, and integration with GNU Make and CMake.
Use it when
- gcc's link-time optimization (LTO) is enabled by adding -flto to both compilation and linking stages.
- gcc's undefined reference error means a symbol was declared but not defined or linked.
Verify before relying
Read SKILL.md below before installing (3 files). Open directory: indexed for reading, not audited.
Install
mohitmishra786/low-level-dev-skills/gcc · repository language: JavaScript
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What are the best GCC optimization flags for a release build?
gcc's release build typically uses -O2 or -O3 for optimization. -O2 balances speed and compile time with good safety; -O3 enables aggressive optimizations but may increase code size and compile time. Pair with -DNDEBUG to disable assertions, -s to strip symbols, and -flto for link-time optimization. For size-constrained builds, use -Os instead. Always profile your specific workload to choose between -O2 and -O3.
How do I enable link time optimization in GCC?
gcc's link-time optimization (LTO) is enabled by adding -flto to both compilation and linking stages. Compile with `gcc -flto -O2 -c file.c` and link with `gcc -flto -O2 file.o -o executable`. LTO allows the compiler to optimize across translation unit boundaries, often reducing binary size and improving performance. Use -flto=auto to parallelize LTO during linking, or -flto=N to use N parallel jobs.
How do I fix a gcc compilation error about undefined reference?
gcc's undefined reference error means a symbol was declared but not defined or linked. Check: (1) all .o files are linked together, (2) required libraries are linked with -lname, (3) symbol names match (case-sensitive, no name mangling mismatches), (4) link order is correct (dependents before dependencies). Use `nm` to inspect object files and verify symbols exist. For C++ code, ensure extern "C" is used for C symbols.
What gcc flags should I use for debug builds?
gcc debug builds use -g to include debugging symbols, -O0 to disable optimization for accurate stepping, and optionally -DDEBUG for conditional debug code. Use -Wall -Wextra for comprehensive warnings. For sanitizers, add -fsanitize=address or -fsanitize=undefined to catch runtime errors. Keep -O0 with sanitizers to avoid optimizations that obscure bugs. Never strip symbols with -s in debug builds.
How do I enable profile-guided optimization with GCC?
gcc's profile-guided optimization (PGO) uses two passes: (1) Compile with -fprofile-generate: `gcc -O2 -fprofile-generate file.c -o prog`, run the program on representative input to generate .gcda files, (2) Recompile with -fprofile-use: `gcc -O2 -fprofile-use file.c -o prog`. PGO lets the compiler optimize based on actual runtime behavior, often yielding 5-15% performance gains over static optimization.
What gcc sanitizer flags are available for runtime safety checks?
gcc's sanitizer flags instrument code to detect runtime errors. -fsanitize=address detects memory errors, -fsanitize=undefined catches undefined behavior, -fsanitize=thread finds data races, -fsanitize=leak detects memory leaks. Combine multiple: -fsanitize=address,undefined. Always compile and link with the same sanitizer flag. Sanitizers add overhead; use only in debug/testing builds. Set ASAN_OPTIONS or UBSAN_OPTIONS environment variables to control behavior.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
GCC
Purpose
Guide agents through GCC invocation: flag selection, build modes, warning triage, PGO, LTO, and common error patterns. Assume the project uses GNU Make, CMake, or a shell script.
Triggers
- "What flags should I use for a release build?"
- "GCC is giving me a warning/error I don't understand"
- "How do I enable LTO / PGO with GCC?"
- "How do I compile with
-fsanitize?" - "My binary is too large / too slow"
- Undefined reference errors, ABI mismatch, missing symbols
Workflow
1. Choose a build mode
| Goal | Recommended flags |
|---|---|
| Debug | -g -O0 -Wall -Wextra |
| Debug + debuggable optimisation | -g -Og -Wall -Wextra |
| Release | `-O2 |
(truncated - see the full file via the links below)
File tree — 3 files
skills/compilers/gcc/SKILL.md
skills/compilers/gcc/references/examples.md
skills/compilers/gcc/references/flags.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Select appropriate GCC flags for debug vs release builds”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
Master Clang's superior diagnostics, optimization remarks, and static analysis capabilities. Learn to interpret inlining and vectorization decisions, configure clang-tidy for automated checks, and leverage ThinLTO for faster builds with comparable code quality.
Master linker selection, essential flags, and link-order resolution for GNU ld, gold, and lld. Learn to enable LTO with GCC or Clang, strip dead code with --gc-sections, and debug common linker errors like undefined symbols and circular dependencies.
Dive into compiler internals: understand why loops fail to vectorize, how register pressure causes spills, and when to deploy PGO or BOLT. Covers mid-level IR optimizations, instruction selection, and post-link optimization strategies with practical triage workflows.
Master DWARF debug format fundamentals—the sections that store type, variable, and function metadata in ELF binaries. Learn to inspect debug info with dwarfdump and readelf, work with split DWARF (.dwo files) to reduce linker overhead, configure debuginfod for remote symbol servers, and navigate how LTO and stripping affect debug information.
Master Windows C/C++ compilation with MSVC cl.exe and clang-cl. This skill maps GCC/Clang flags to MSVC equivalents, explains runtime library choices (/MT vs /MD), guides PDB setup for debugging, and diagnoses common linker failures. Use it when configuring Visual Studio builds, MSBuild projects, or switching to clang-cl as a drop-in MSVC replacement.
This skill guides you through building maintainable Makefiles for C/C++ using phony targets, pattern rules, and automatic dependency tracking. Learn to structure multi-file projects, manage compiler flags, diagnose rebuild issues, and convert ad-hoc compile commands into robust build systems.
More skills binary-hardening (MIT) · cmake (MIT) · containers-internals (MIT)