How to deal with Makefile error: make: *** [Makefile:11: test] Error 3

How to deal with Makefile error: make: *** [Makefile:11: test] Error 3

我正在尝试为我的代码构建一个 Makefile,出于某种原因,我得到了

./ex2_q1 11 24 36 7 5

There were 3 prime numbers

make: *** [Makefile:11: test] Error 3

第二行是程序的输出。 一切似乎都正常,但我不知道为什么会出现错误。

Makefile 是:

PROG = ex2_q1

all: test

test: ex2_q1
    ./ex2_q1 11 24 36 7 5

factors.o: factors.c
    gcc -Wall -c factors.c

ex2_q1.o: ex2_q1.c
    gcc -Wall -c ex2_q1.c

clean: 
    rm -vf *.o $(PROG)
    rm -vf *.o factors
    rm -vf *.txt
    rm -vf *.log

factors: factors.o
    gcc -o factors -Wall factors.o

ex2_q1: ex2_q1.o factors
    gcc -o ex2_q1 -Wall ex2_q1.o

您的程序 ex2_q1 被调用为 ./ex2_q1 11 24 36 7 5 returns 非零结果。这表示存在错误,正确的解决方法是修复您的程序。如果您无法修复程序,您可以通过将配方更改为 ./ex2_q1 11 24 36 7 5 || true 来消除错误。如果您仍然想要错误消息但继续构建,您可以 运行 使用 -k 标志制作,或者您可以在配方前加上 -:

test: ex2_q1
    - ./ex2_q1 11 24 36 7 5