FAQ – Sample Makefile for C and C++

1.Makefile for C and C++ in Linux
+Makefile is the file contain gcc/g++ commands to compile the source files in an order
+The Makefile name is “Makefile”. NO EXTENSION.
+We must place the Makefile in the same folder with the source file
+To start compile > type “make” to compile

+Sample Makefile for C/C++ EXECUTABLE program:
//——————————
all: myprog.c
   gcc -g -Wall -o myprog myprog.c
clean:
   $(RM) myprog
//——————————

+Sample Makefile for C/C++ Shell Script Linux Kernel:
//——————————
obj-m+=assignment.o

all:
   make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
clean:
   make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean
//——————————

Add Comment