Makefile to compile multiple C programs?

前端 未结 8 1154
予麋鹿
予麋鹿 2020-12-02 09:41

This is an incredibly simple question, but I\'m new to makefiles. I am trying to make a makefile that will compile two independent programs:

program1:
    gc         


        
8条回答
  •  离开以前
    2020-12-02 10:28

    SRC = a.cpp b.cpp
    BIN = $(patsubst %.cpp,%,$(SRC))
    
    all: $(BIN)
    
    clean:
        rm -f $(BIN)
    
    .PHONY: all clean
    

    make all will do:

    c++     a.cpp   -o a
    c++     b.cpp   -o b
    

    If you set CXX and CXXFLAGS variables make will use them.

提交回复
热议问题