2.2.7. Example: Building a C program with the GCC (compiling and linking in one step)
To build a basic C program, use GCC to compile source code directly into an executable. This single-step compilation command creates a foundation for developing simple applications on Red Hat Enterprise Linux.
Procedure
Create a directory
hello-c:$ mkdir hello-cChange to the created directory:
$ cd hello-cCreate file
hello.cwith the following contents:#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }Compile and link the code with GCC:
$ gcc hello.c -o helloworldThis compiles the code, creates the object file
hello.o, and links the executable filehelloworldfrom the object file.Run the resulting executable file:
$ ./helloworldHello, World!
Additional resources