Makefile可执行错误

时间:2016-11-13 04:55:48

标签: c makefile

我有以下Makefile:

all: test.c test1.c
    gcc -o test test.c -lm
    gcc -o test1 test1.c
    ./test 1000 input.txt

我收到的错误如./test 1000 input.txt make: *** [run] Error 255。 Makefile是否正确?

1 个答案:

答案 0 :(得分:1)

./test 1000 input.txt make: *** [run] Error 255

这并不意味着您的Makefile有任何问题。这意味着您的./test程序已退出状态为255。

你没有向我们展示test.c,但我假设你没有写return 255;。由于退出状态通常只有8位,因此您可能(错误地)写了return -1。你也可能(错误地)省略了main的返回语句,这导致了未定义的行为,而-1恰好位于返回值寄存器中(x86上的eax)。

您应始终启用编译器警告。为了强制您纠正它们,这些警告(通常表示代码损坏)应该导致编译失败。

CFLAGS = -Wall -Wextra -Werror

test: test.c
        $(CC) $(CFLAGS) -o $@ $^
相关问题