C
Beginner
1 min read
Compiling C with GCC
Example
/*
* Demonstrating common GCC compilation flags.
*
* Compile (basic):
* gcc greet.c -o greet
*
* Compile (recommended for development):
* gcc -Wall -Wextra -std=c11 -g greet.c -o greet
*
* Preprocess only (see macro expansion):
* gcc -E greet.c
*
* Compile to assembly:
* gcc -S greet.c # produces greet.s
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc < 2) {
fprintf(stderr, "Usage: %s <name>\n", argv[0]);
return EXIT_FAILURE; /* EXIT_FAILURE == 1 on most systems */
}
printf("Hello, %s!\n", argv[1]);
return EXIT_SUCCESS; /* EXIT_SUCCESS == 0 */
}