LAB4 Preparation
GCC (GNU Compiler Collection)
GCC is a compiler that compiles C, C++, and other languages into executable code. It’s widely used in many development environments, especially in Unix-like systems (like Linux).
Ex:gcc -o output_file source_file.c
Make and Makefile
Make is a utility that helps automate the process of building programs by checking which parts of the code need to be recompiled, and a Makefile is a script that defines how the program should be built, including which files to compile and the order in which tasks should be performed.
Example:
# Variables
CC = gcc
CFLAGS = -Wall -g
OBJ = main.o utils.o
TARGET = my_program
# Default target
all: $(TARGET)
# Create the executable from object files
$(TARGET): $(OBJ)
$(CC) $(CFLAGS) -o $@ $^
# Compile .c files into .o files
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Clean up object files and executable
clean:
rm -f *.o $(TARGET)
Example:(Ref:http://spo600.cdot.systems/doku.php?id=spo600:make_and_makefiles)
CC=cc CFLAGS=-O3 all: half double half: half.o sauce.o ${CC} ${CFLAGS} -o half half.o sauce.o double: double.o sauce.o ${CC} ${CFLAGS} -o double double.o sauce.o half.o: half.c number.h ${CC} ${CFLAGS} -c half.c double.o: double.c number.h ${CC} ${CFLAGS} -c double.c sauce.o: sauce.c ${CC} ${CFLAGS} -c sauce.c
Comments
Post a Comment