简体   繁体   中英

How do I make a target in a makefile invoke another target in the makefile

So I have this makefile and I want the target all just to invoke the target expertest, but apparently the way I'm doing it is wrong because i'm getting the error "make: exprtest: Command not found make: * [all] Error 127 " this is the makefile:

all:
    exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
    g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o
driver.o: driver.cpp scanner.hpp driver.hpp
    g++ -Wall -g -c driver.cpp
parser.tab.o: parser.tab.hpp parser.tab.cpp
    bison parser.ypp
    g++ -Wall -g -c parser.tab.cpp
scanner.o: scanner.cpp scanner.hpp
    flex -t scanner.ll > scanner.cpp
    g++ -Wall -g -c scanner.cpp
clean:
    rm parser.tab.hpp parser.tab.cpp scanner.cpp

Put exprtest on the same line as all . Dependencies come after the colon, commands come on the following lines, indented.

target: dependencies
[tab] system command

So in your case it all becomes:

all: exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
    g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o

And you can always have make call a new instance of make .
For example:

all:
    $(MAKE) exprtest

exprtest:  
    do exprtest stuff

Typing make all will indirectly do make exprtest .

You want to do something like

all: exprtest

What that says is " all depends on exprtest to be successful".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM