Loading...
Loading...
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.
npx skill4agent add mohitmishra786/low-level-dev-skills gcc-fsanitize| Goal | Recommended flags |
|---|---|
| Debug | |
| Debug + debuggable optimisation | |
| Release | |
| Release (max perf, native only) | |
| Release (min size) | |
| Sanitizer (dev) | |
-std=c11-std=c++17-Wall -Wextra-Wpedantic-Werror#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
// ...
#pragma GCC diagnostic pop-w-g-g3macro expand-ggdb-gsplit-dwarf.dwodebuginfod-g-Og-O0Need 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-O2-O3-funswitch-loops-fpeel-loops-floop-interchange-O3-Ofast-ffast-math# 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 proggcc-argcc-ranlibarranlib-flto=automake-flto=Nskills/binaries/linkers-lto# 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-correctiongcc -E file.c | lessgcc -dM -E - < /dev/null-std=c11 -pedantic-errors-std=c11-std=gnu11| Symptom | Likely cause | Fix |
|---|---|---|
| Missing | Add |
| Variable defined (not just declared) in a header | Add |
| Missing | Add the header |
| Wrong cast or missing prototype | Fix the type; check headers |
| ABI errors with C++ | Mixed | Unify |
| Overflow on a 32-bit relative relocation | Use |
skills/runtimes/sanitizers# 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 marchskills/runtimes/sanitizers-fsanitize=*skills/compilers/clangskills/binaries/linkers-ltoskills/debuggers/gdb