makefile编译多个C程序?

问题描述:

Increadibly简单的问题,但我是新来的makefile,我试图做一个makefile,将编译应用两个独立的程序。所有在线的例子进入的方式更多的细节比我更需要,而且混乱!

Increadibly simple question but I'm new to makefiles and am trying to make a makefile that will compile two independant programs. All the examples online go into way more details than I need and are confusing!

我有以下内容:

program1:
    gcc -o prog1 program1.c

program2
    gcc -o prog2 program2.c

我真正想要做的它是运行在两个gcc的线条。我在做什么错了?

All I really want it do is to run the two gcc lines. What am I doing wrong?

做到像这样

all: program1 program2

program1: program1.c
    gcc -o program1 program1.c

program2: program2.c
    gcc -o program2 program2.c

你说你不想先进的东西,但你也可以缩短它像这样基于一些默认规则。

You said you don't want advanced stuff, but you could also shorten it like this based on some default rules.

all: program1 program2

program1: program1.c
program2: program2.c