0

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
missyj
  • 47
  • 1
  • 1
  • 7

1 Answers1

3

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.

Community
  • 1
  • 1
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261