linux编程之编写Makefile文件

1、用make程序来执行Makefile,make的

$ sudo apt install make -y

2、先看一个完整的Makefile示例吧,下面的Makefile会把一个main.cpp或main.c编译成一个main程序:

LINK    = @echo linking $@ && g++
GCC     = @echo compiling $@ && g++
GC      = @echo compiling $@ && gcc
AR      = @echo generating static library $@ && ar crv
FLAGS   = -g -DDEBUG -W -Wall -fPIC
GCCFLAGS = DEFINES = HEADER  = -I./LIBS    = LINK
FLAGS =
#HEADER += -I./
#LIBS    += -lrt
#LIBS    += -pthread
OBJECT := main.o
BIN_PATH = ./TARGET = main

$(TARGET) : $(OBJECT)
    $(LINK) $(FLAGS) $(LINKFLAGS) -o $@ $^ $(LIBS)
.cpp.o:
    $(GCC) -c $(HEADER) $(FLAGS) $(GCCFLAGS) -fpermissive -o $@ $<
.c.o:
    $(GC) -c $(HEADER) $(FLAGS) -fpermissive -o $@ $<
install: $(TARGET)
    cp $(TARGET) $(BIN_PATH)
clean:
    rm -rf $(TARGET) *.o *.so *.a
(0)

相关推荐