Hello;
I am trying to understand makefiles. So I can write a simple makefile code. I want to ask questions for better understanding.
so here is my code :
Code:
CC = gcc
CFLAGS = -g -Wall
FILE = main
EXECUTABLE_FILE = out_executable
all : $(FILE)
$(CC) -O2 $(CFLAGS) -o $(EXECUTABLE_FILE) $(FILE).c
clean :
$(RM) *~ $(FILE) *~ $(EXECUTABLE_FILE) *.o
what does -o mean in this example ?
thank you.
I understand.
gcc [options] [source files] [object files] -o output file
and -o is gcc option flag and it write the build output to an output file.
$(CC) -O2 $(CFLAGS) $(FILE).c -o $(EXECUTABLE_FILE) is also work.
but why $(CC) -O2 $(CFLAGS) -o $(EXECUTABLE_FILE) $(FILE).c is work ?
The line calls gcc. -o is a gcc command line option, you'll review the gcc user manual to know what it means.
-o file
Place output in file file. This applies regardless to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.