0% found this document useful (0 votes)
55 views1 page

GCC Command

To compile a C program using gcc, use the command 'gcc program.c' which generates an executable named a.out by default. You can run this executable with './a.out' and specify a different output file using the '-o' option. Additionally, to link libraries, use the '-l' option, such as '-lm' for the math library.

Uploaded by

haris khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views1 page

GCC Command

To compile a C program using gcc, use the command 'gcc program.c' which generates an executable named a.out by default. You can run this executable with './a.out' and specify a different output file using the '-o' option. Additionally, to link libraries, use the '-l' option, such as '-lm' for the math library.

Uploaded by

haris khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Compiling and Running C Programs

You can compile your program with the gcc command. The output of the compiler
command, i.e., the executable program is stored in the [Link] file by default. To
compile a source file titled program.c, type:

$ gcc program.c

You can run the executable program generated by this command by typing./[Link] and
hitting the <Enter> key, as shown in the following session.

$ ./[Link]

[ ... program output ... ]

You can store the executable program in a specific file by using the –o option. For
example, in the following session, the executable program is stored in the
assignment file.

$ gcc program.c –o assignment

The gcc compiler does not link many libraries automatically. You can link a library
explicitly by using the –l option. In the following session, we are asking the
compiler to link the math library with our object file as it creates the executable
file.

$ gcc program.c –o assignment -lm

$ assignment

[ ... program output ... ]

You might also like