{
  "id": 6680863,
  "title": "GCC Flags Notes",
  "url": "https://urgent.news/2026/09/11/gcc-flags-notes",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-11T01:13:27.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/csm18/gcc-flags-notes-5h51"
  },
  "original_language": "en",
  "account": "GNU C Compiler (GCC) flags allow users to control the compilation process. The -c flag compiles source code into an object file without linking it into an executable. The resulting object file has a .o extension. The output filename is specified using the -o flag. For example, gcc main.c -o main produces an executable named main.\n\nLinking a library is done using the -l flag followed by the library name. For instance, gcc main.c -lm -o main links the math library (libm) and produces an executable named main. The library must be present in the standard search paths of GCC.\n\nThe -I flag specifies an additional directory to search for header files. For example, gcc -Iinclude main.c -o main searches for header files in the include/ directory. The -L flag specifies an additional directory to search for libraries during linking. For example, gcc main.c -L ./lib -lmylib -o main searches for libraries in ./lib and links libmylib to produce an executable named main.\n\nThe -static flag tells the linker to create a statically linked executable. This means the executable includes copies of all required libraries, rather than relying on external libraries. The -static flag allows the executable to run without needing to locate libraries in system directories.\n\nOptimization flags are used to improve the performance of the compiled code. The -O flag sets the level of optimization. For example, gcc -O2 main.c -o main sets the optimization level to 2, which produces smaller and faster binaries. The optimization levels range from 0 (does nothing) to 3 (produces fast binaries, may not be small in size). The -O1 flag is suitable for fast compile times, while -O2 is recommended for production environments.\n\nAdditional optimization-related flags include -O0 (does nothing), -O1 (basic optimization), -O2 (smaller binaries), and -O3 (faster binaries, may not be small). The -O flag can also be combined with other optimization-related flags, such as -flto (link-time optimization).\n\nThe -std flag specifies the C standard the compiler should follow. For example, gcc -std=c17 main.c -o main compiles code according to the C17 standard. Some common C standards include C89, C99, C11, and C17.\n\nSeveral warning-related flags are available to help identify potential issues in the code. The -Wall flag enables all warning messages. The -Wextra flag adds additional warnings not included in -Wall. The -Wpedantic flag warns about nonstandard C constructs, while -Werror treats warnings as errors, causing the compilation to fail if any warnings are issued.\n\nDebugging-related flags help generate debugging information in the executable or object file. The -g flag generates debugging information, allowing debuggers like GDB to provide more detailed debugging information. This is particularly useful for identifying issues during development.\n\nLastly, the -E flag runs only the preprocessor, without compiling the code. This can be helpful for examining preprocessed code or identifying issues with header files. The -D flag defines a macro from the command line. For example, gcc -DTEST main.c expands the macro TEST during preprocessing.",
  "summary": "My notes on GNU C Compiler (GCC) Flags Basic Flags -c It tells GCC to compile the source file into an object file (.o), but do not link it into an executable. gcc -c main.c This produces: main.o Then you can link it separately: gcc main.o -o main -o It specifies the output filename. gcc main.c -o main We get: main -l It means \"link this library\". For example: gcc main.c -lm -o main Here: -l ->…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}