I am having trouble compiling and running my C program. What are the commands?

53 views Asked by At

I am having trouble compiling and running my C program. What are the commands?

My code is:

#include <stdio.h>
int main(){
   printf("Hello World!\n");
   exit(0);
}

I tried compiling with

gcc -o hello.c

only to be unsuccessful. I am using a Mac terminal, if that matters.

1

There are 1 answers

0
Sourav Ghosh On

In gcc, option -o is used to specify a custom output filename. The immediate next argument should be the file name.

-o file

Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.

A simple revised command will be

gcc -o hello hello.c 

where, hello is the name of the binary.

You can check the online gcc manual for more info.