Makefile to compile multiple C programs?

前端 未结 8 1184
予麋鹿
予麋鹿 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:14

    This will compile all *.c files upon make to executables without the .c extension as in gcc program.c -o program.

    make will automatically add any flags you add to CFLAGS like CFLAGS = -g Wall.

    If you don't need any flags CFLAGS can be left blank (as below) or omitted completely.

    SOURCES = $(wildcard *.c)
    EXECS = $(SOURCES:%.c=%)
    CFLAGS = 
    
    all: $(EXECS)
    

提交回复
热议问题