从makefile运行可执行文件2
问题描述:
我应该为我的makefile做些什么,不仅可以编译和编译“test”,而且可以在终端中输入“make test”时实际运行它,所以我不必每次都做./test ?从makefile运行可执行文件2
LDFLAGS = -lm -L. -lhashi
CFLAGS = -g -Wall -std=c99
SRC=$(wildcard *.c)
OBJETS = $(SRC:.c=.o)
all : prog1 prog2 test
...
test : test_game1.o test_toolbox.o libhashi.a
$(CC) $^ $(LDFLAGS) -o [email protected]
test_game1.o : test_game1.c game.h node.h test_toolbox.h test_game_eliott.c test_game_flo.c test_game_iana.c test_game_remi.c
test_toolbox.o : test_toolbox.c test_toolbox.h
clean :
rm -f ... test_game1.o test_toolbox.o test ...
答
你需要一个假目标。 (https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html)。
例如:
.PHONY: run-test
run-test: test
./test
test: test_game1.o test_toolbox.o libhashi.a
$(CC) $^ $(LDFLAGS) -o [email protected]
具有不同的目标运行测试保持构建测试而不执行它的可能性。
我刚刚检查了GNU Make 4.1并且'.phony'不起作用。它必须是'.PHONY'(全部大写) –
谢谢你的回应,结果有点奇怪,因为它运行它,但它说:make:*** [test]错误1 – Iana
运行命令(例如“./test”),检查它的退出状态。退出状态不为0时,表示发生错误,并且会报告错误。 – FrancoisB