organize project and specify directory for object files in Makefile

前端 未结 5 2136
时光取名叫无心
时光取名叫无心 2021-02-09 16:23

Here are my two questions:

  1. I am now learning to manage my code with CVS, and I just want to make a repository for my C++ files, Makefile and bash and python scri

5条回答
  •  我寻月下人不归
    2021-02-09 16:32

    If you want to learn make, the GNU make manual is very good, both as a reference and a tutorial. You might want to consider using the patsubst command. The following is a chopped down version of one of my own makefiles that uses it:

    OUT = bin/csvfix.exe
    CC = g++
    IDIR = inc
    ODIR = obj
    SDIR = src
    INC = -Iinc -I../alib/inc
    LIBS = ../alib/lib/alib.a -lodbc32 
    
    _OBJS = csved_atable.o \
            csved_case.o \
            csved_cli.o \
            csved_command.o \
            csved_date.o \
    
    OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
    
    $(ODIR)/%.o: $(SDIR)/%.cpp 
        $(CC) -c $(INC) -o $@ $< $(CFLAGS) 
    
    $(OUT): $(OBJS)
        $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
        strip $(OUT)
    
    clean:
        rm -f $(ODIR)/*.o $(OUT)
    

提交回复
热议问题