Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8253685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:57:33+00:00 2026-06-08T00:57:33+00:00

The GNU make manual says It is possible that more than one pattern rule

  • 0

The GNU make manual says

It is possible that more than one pattern rule will meet these criteria. In that case, make will choose the rule with the shortest stem (that is, the pattern that matches most specifically).

So it surprised me that:

$ touch make_specific.cpp

$ cat Makefile.general_first
%.o: %.cpp
@echo using general rule
$(CXX) -c $< -o $@

%_specific.o: %_specific.cpp
@echo using specific rule
$(CXX) -c $< -o $@

$ make -B -f Makefile.general_first make_specific.o
using general rule
g++44 -c make_specific.cpp -o make_specific.o

Multiple pattern rules match the target, and since the stem for the %_specific.o : %_specific.cpp rule (‘make’ in this case) is shorter than the stem for the %.o : %.cpp rule, I expected the specific rule to be selected, but it’s not.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:57:35+00:00Added an answer on June 8, 2026 at 12:57 am

    You are probably using a make version lower than 3.82.

    In version 3.81 and lower, the selection criterion was different; make would choose the first rule that matched the pattern. The documentation you are referring to is for version 3.82. That version does choose the rule with the most specific stem, which is according to your expectations.

    From the file NEWS in the make source tree:

    Version 3.82
    ...
    * WARNING: Backward-incompatibility!
      The pattern-specific variables and pattern rules are now applied in the
      shortest stem first order instead of the definition order (variables
      and rules with the same stem length are still applied in the definition
      order). This produces the usually-desired behavior where more specific
      patterns are preferred. To detect this feature search for 'shortest-stem'
      in the .FEATURES special variable.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using GNU make, is it possible to create a set of targets that will
With GNU Make and one of the compilers in gcc: Is it possible to
I'd like to define a GNU make pattern rule with the dependencies in a
I'm using GNU Make 3.81, and I have the following rule in my Makefile:
I'm learning to work with GNU make and I'm reading the manual (which is
I am using GNU make 3.81. Here is a test makefile that demonstrates the
I am using GNU make. In a Makefile that I got, i see the
From section 4.14 Generating Prerequisites Automatically of GNU make manual %.d: %.c @set -e;
GNU/Make manual §5.7 states the following: 5.7 Recursive Use of make Recursive use of
I'm using (GNU) Make in my project. I'm currently putting one makefile per directory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.