
gcc
GCC compiler skill for C/C++ projects. Use when selecting optimization levels, warning flags, debug builds, LTO, sanitizer instrumentation, or diagnosing compilation errors with GCC. Covers flag selection for debug vs release, ABI concerns, preprocessor macros, profile-guided optimization, and integration with build systems. Activates on queries about gcc flags, compilation errors, performance tuning, warning suppression, or cross-standard compilation.
- Installs
- 693
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill gcc- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads gcc automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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 -DNDEBUG -Wall |
| Release (max perf, native only) | -O3 -march=native -DNDEBUG |
| Release (min size) | -Os -DNDEBUG |
| Sanitizer (dev) | -g -O1 -fsanitize=address,undefined |
Always pass -std=c11 / -std=c++17 (or the required standard) explicitly. Never rely on the implicit default.
2. Warning discipline
Start with -Wall -Wextra. For stricter standards compliance add -Wpedantic. To treat all warnings as errors in CI: -Werror.
Suppress a specific warning only in a narrow scope:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
// ...
#pragma GCC diagnostic pop
Do not pass -w (silences everything) except as a last resort for third-party headers.
3. Debug information
-g— DWARF debug info, default level 2-g3— includes macro definitions (useful with GDBmacro expand)-ggdb— DWARF extensions optimal for GDB-gsplit-dwarf— splits.dwofiles; reduces link time, needed fordebuginfod
Pair -g with -Og (not -O0) when you need readable optimised code in GDB.
4. Optimisation decision tree
Need max throughput on a fixed machine?
yes -> -O3 -march=native -flto
no -> profiling available?
yes -> -O2 -fprofile-use
no -> -O2
Size-constrained (embedded, shared lib)?
yes -> -Os (or -Oz with clang)
-O3 vs -O2: -O3 adds aggressive loop transformations (-funswitch-loops, -fpeel-loops, -floop-interchange) and more aggressive inlining. Use -O3 only after benchmarking; it occasionally regresses due to i-cache pressure.
-Ofast: enables -ffast-math which breaks IEEE 754 semantics (NaN handling, associativity). Avoid unless the numerical domain explicitly permits it.
5. Link-time optimisation (LTO)
# Compile
gcc -O2 -flto -c foo.c -o foo.o
gcc -O2 -flto -c bar.c -o bar.o
# Link (must pass -flto again)
gcc -O2 -flto foo.o bar.o -o prog
Use gcc-ar / gcc-ranlib instead of ar / ranlib when archiving LTO objects into static libs.
For parallel LTO: -flto=auto (uses make-style jobserver) or -flto=N.
See references/flags.md for full flag reference. See skills/binaries/linkers-lto for linker-level LTO configuration.
6. Profile-guided optimisation (PGO)
# Step 1: instrument
gcc -O2 -fprofile-generate prog.c -o prog_inst
# Step 2: run with representative workload
./prog_inst < workload.input
# Step 3: optimise with profile
gcc -O2 -fprofile-use -fprofile-correction prog.c -o prog
-fprofile-correction handles profile data inconsistencies from multi-threaded runs.
7. Preprocessor and standards
- Inspect macro expansion:
gcc -E file.c | less - Dump predefined macros:
gcc -dM -E - < /dev/null - Force strict standard:
-std=c11 -pedantic-errors - Disable GNU extensions:
-std=c11(not-std=gnu11)
8. Common error triage
| Symptom | Likely cause | Fix |
|---|---|---|
undefined reference to 'foo' | Missing -lfoo or wrong link order | Add -lfoo; move -l flags after object files |
multiple definition of 'x' | Variable defined (not just declared) in a header | Add extern in header, define in one .c |
implicit declaration of function | Missing #include | Add the header |
warning: incompatible pointer types | Wrong cast or missing prototype | Fix the type; check headers |
| ABI errors with C++ | Mixed -std= or different libstdc++ | Unify -std= across all TUs |
relocation truncated | Overflow on a 32-bit relative relocation | Use -mcmodel=large or restructure code |
For sanitizer reports, use skills/runtimes/sanitizers.
9. Useful one-liners
# Show all flags enabled at -O2
gcc -Q --help=optimizers -O2 | grep enabled
# Preprocess only (check includes/macros)
gcc -E -dD src.c -o src.i
# Assembly output (Intel syntax)
gcc -S -masm=intel -O2 foo.c -o foo.s
# Show include search path
gcc -v -E - < /dev/null 2>&1 | grep -A20 '#include <...>'
# Check if a flag is supported
gcc -Q --help=target | grep march
For a complete flag cheatsheet, see references/flags.md. For common error patterns and examples, see references/examples.md.
Related skills
- Use
skills/runtimes/sanitizersto add-fsanitize=*builds - Use
skills/compilers/clangwhen switching to clang/LLVM - Use
skills/binaries/linkers-ltofor advanced LTO linker flags - Use
skills/debuggers/gdbfor debugging GCC-built binaries
FAQ
What does the gcc skill do?
GCC compiler skill for C/C++ projects. Use when selecting optimization levels, warning flags, debug builds, LTO, sanitizer instrumentation, or diagnosing compilation errors with GCC. Covers flag selection for debug vs release, ABI concerns, preprocessor macros, profile-guided optimization, and integration with build systems. Activates on queries about gcc flags, compilation errors, performance tuning, warning suppression, or cross-standard compilation.
How do I install gcc?
Run npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill gcc in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/gcc/ (personal) or .claude/skills/gcc/ (project).
Which AI agents can use gcc?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is gcc safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains gcc?
It is published by mohitmishra786 in mohitmishra786/low-level-dev-skills. It has 693 recorded installs.
More from mohitmishra786/low-level-dev-skills
cmake
mohitmishra786/low-level-dev-skills
CMake build system skill for C/C++ projects. Use when writing or refactoring CMakeLists.txt, configuring out-of-source builds, selecting generators (Ninja, Make, VS), managing targets and dependencies with targetlinklibraries, integrating external packages via findpackage or FetchContent, enabling sanitizers, setting up toolchain files for cross-compilation, or exporting CMake packages. Activates on queries about CMakeLists.txt, cmake configure errors, target properties, install rules, CPack, or CMake presets.
static-analysis
mohitmishra786/low-level-dev-skills
Static analysis skill for C/C++ codebases. Use when hardening code quality, triaging noisy builds, running clang-tidy, cppcheck, or scan-build, interpreting check categories, suppressing false positives, or integrating static analysis into CI. Activates on queries about clang-tidy checks, cppcheck, scan-build, compilecommands.json, code hardening, or static analysis warnings.
gdb
mohitmishra786/low-level-dev-skills
GDB debugger skill for C/C++ programs. Use when starting a GDB session, setting breakpoints, stepping through code, inspecting variables, debugging crashes, using reverse debugging (record/replay), remote debugging with gdbserver, or loading core dumps. Activates on queries about GDB commands, segfaults, hangs, watchpoints, conditional breakpoints, pretty-printers, Python GDB scripting, or multi-threaded debugging.
llvm
mohitmishra786/low-level-dev-skills
LLVM IR and pass pipeline skill. Use when working directly with LLVM Intermediate Representation (IR), running opt passes, generating IR with llc, inspecting or writing LLVM IR for custom passes, or understanding how the LLVM backend lowers IR to assembly. Activates on queries about LLVM IR, opt, llc, llvm-dis, LLVM passes, IR transformations, or building LLVM-based tools.
sanitizers
mohitmishra786/low-level-dev-skills
Compiler sanitizer skill for runtime bug detection in C/C++. Use when enabling and interpreting AddressSanitizer (ASan), UndefinedBehaviorSanitizer (UBSan), ThreadSanitizer (TSan), MemorySanitizer (MSan), or LeakSanitizer (LSan) with GCC or Clang. Activates on queries about sanitizer flags, sanitizer reports, ASANOPTIONS, memory errors, data races, undefined behaviour, uninitialised reads, or choosing which sanitizer to use for a given bug class.
core-dumps
mohitmishra786/low-level-dev-skills
Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.