Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
Makefile overriding default implicit rule

Why this rule cannot override the default implicit rule ?

When make is invoked like: make myapp (suppose myapp.c is there). The make runs the default command to build and link the program instead the commands defined in this implicit rule:

#... omitted code
LCUS=$(LIBS)/libcus.a

#... omitted code
% : %.o $(LCUS)
        echo  !!! Custom build !!!
        $(MY_CMD) $< -o $@ $(LCUS)
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Taken from the GNU online make manual:

You can override a built-in implicit rule (or one you have defined yourself) by defining a new pattern rule with the same target and prerequisites, but different commands.

So I would assume it is because the prerequisites are not the same as the implicit rule.

Also take from the make manual:

Linking a single object file n is made automatically from n.o by running the linker (usually called ld) via the C compiler. The precise command used is $(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS). This rule does the right thing for a simple program with only one source file. It will also do the right thing if there are multiple object files (presumably coming from various other source files), one of which has a name matching that of the executable file. Thus,

 x: y.o z.o

when x.c, y.c and z.c all exist will execute:

cc -c x.c -o x.o
cc -c y.c -o y.o
cc -c z.c -o z.o
cc x.o y.o z.o -o x
rm -f x.o
rm -f y.o
rm -f z.o

So basically make understands implicit rules for program files that are generated from .o files but when you throw in your static library it doesn't understand. A simple way to test would be to remove $(LCUS) from your dependencies (as a temporary measure) to see if it then uses your rule instead of the built in one. If it does then you know that is your problem. If simply adding myapp in replace of % is a problem because you want the rule to build multiple targets you can try the following:

$(APPS): % : %.o $(LCUS)

where $(APPS) is a variable containing all the applications you wish to build. This will allow one rule to build multiple targets. You could also skip the use of the variable altogether and place a space separated list. This is an example of a static pattern rule, more information can be found here. The difference between static pattern and implicit rules can be found here.

over 4 years ago · Santiago Trujillo Relatório

0

Your rule isn't the same as the built-in implicit rule so it doesn't cancel it.

Additionally, make always prefers a rule that doesn't require intermediate files to be built to one that does. If you pre-create the .a file make might use your rule instead (but it might not even still).

If you cancel the built-in rule and leave your rule in place it should work correctly I believe.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda