0
votes

I'm trying to make a makefile for compiling various examples that are within a subfolder. The makefile consisting of just:

S_1_2.exe : Twister.cpp Parsing.cpp ./Surfaces/S_1_2.cpp
    g++ -o [email protected] $^ -I . -W -Wall

Works fine when run with the command "make S_1_2.exe". However:

%S_1_2.exe : Twister.cpp Parsing.cpp ./Surfaces/S_1_2.cpp
    g++ -o [email protected] $^ -I . -W -Wall

fails, even when run with the command make S_1_2.exe, with the error "make: * No rule to make target 'S_1_2.exe'. Stop."

Shouldn't %S_1_2.exe do pattern matching and so match S_1_2.exe? In which case why is it not matching this rule?

I am using GNU Make 3.81

2
Are you sure that those three source files exist?Beta
Yes, they all exist. Like I said the first command runs fine and that has the exact same dependencies.Mark Bell
I'm running GNUMake 3.81, and I get the same error with %S_1_2.exe, but with %_1_2.exe I get the error only when one of the sources is missing.Beta

2 Answers

1
votes

The percentage symbol matches a non-empty string. So you should use %_1_2.exe or better yet - %.exe. I don't know if there is any other symbol that matches empty strings too.

1
votes

The % is for matching a part of the target against the same part in one or more dependencies. You can't omit it from all dependencies.