{"enrichment":{"faq":[{"a":"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.","q":"What are the best GCC optimization flags for a release build?"},{"a":"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.","q":"How do I enable link time optimization in GCC?"},{"a":"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.","q":"How do I fix a gcc compilation error about undefined reference?"},{"a":"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.","q":"What gcc flags should I use for debug builds?"},{"a":"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.","q":"How do I enable profile-guided optimization with GCC?"},{"a":"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.","q":"What gcc sanitizer flags are available for runtime safety checks?"}],"shadow_tags":["compiler-optimization","build-configuration","error-diagnosis","performance-tuning","memory-safety","debug-symbols","link-time-optimization","warning-management","profiling-instrumentation","standards-compliance"],"summary_rewrite":"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."},"files":[{"bytes":5729,"path":"skills/compilers/gcc/SKILL.md","sha256":"944ca89fab68b2e546fb108dc93ad8e666a68a68c9e2ffdc5ef5e892e54106ae","url":"https://skillfed.io/files/mohitmishra786/low-level-dev-skills/gcc/9249d95a/SKILL.md"}],"id":"mohitmishra786/low-level-dev-skills/gcc","links":{"html":"https://skillfed.io/mohitmishra786/low-level-dev-skills/gcc","md":"https://skillfed.io/mohitmishra786/low-level-dev-skills/gcc.md","repo":"https://github.com/mohitmishra786/low-level-dev-skills"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":19,"language":"JavaScript","last_updated":"2026-06-27","license":"MIT","name":"gcc","publisher":"mohitmishra786","stars":148},"relations":{"similar":[{"id":"mohitmishra786/low-level-dev-skills/clang"},{"id":"mohitmishra786/low-level-dev-skills/pgo"},{"id":"mohitmishra786/low-level-dev-skills/linkers-lto"},{"id":"mohitmishra786/low-level-dev-skills/msvc-cl"},{"id":"mohitmishra786/low-level-dev-skills/make"},{"id":"mohitmishra786/low-level-dev-skills/binary-hardening"},{"id":"mohitmishra786/low-level-dev-skills/llvm"},{"id":"mohitmishra786/low-level-dev-skills/compiler-optimizations-deep"},{"id":"bytedance/agentkit-samples/code-optimization"},{"id":"mohitmishra786/low-level-dev-skills/dwarf-debug-format"}]},"slug":{"owner":"mohitmishra786","repo":"low-level-dev-skills","skill":"gcc"},"version":"9249d95a"}
