Makefile通配符依赖项

Oli*_*ier 6 c++ makefile

我想使用通配符将所有.cpp和.cc文件包含在目标的依赖项中.

目前,我必须做以下事情:

all: main.cpp file1.cc file2.cc
    g++ -O3 -o all main.cpp file1.cc file2.cc -I./include -L./lib
Run Code Online (Sandbox Code Playgroud)

以下似乎不起作用:

all: %.cpp %.cc
    g++ -O3 -o $@ $^ -I./include -L./lib
Run Code Online (Sandbox Code Playgroud)

我得到错误make:***没有规则来制作目标'%.cc','all'需要.停止.

Qwe*_*yzw 6

targets := $(wildcard *.cpp) $(wildcard *.cc)
all: $(targets)
        g++ $(targets)
Run Code Online (Sandbox Code Playgroud)

这对我有用