在控制台正常工作的Makefile错误 [英] Makefile error that works fine in console
问题描述
我建立一个运行一系列测试,并增加了结果的文件生成文件。在makefile我有这样的设置为:
I am building a makefile that runs a series of tests and adds the results to a file. In the makefile I have this set up as:
runtests:
rm -f results.txt
cardtest1 > results.txt
cardtest2 >> results.txt
cardtest3 >> results.txt
cardtest4 >> results.txt
unittest1 >> results.txt
unittest2 >> results.txt
unittest3 >> results.txt
unittest4 >> results.txt
现在我可以不运行的问题都在这个上面的命令或任何其他命令(提供的RESULTS.TXT文件存在的追加)的。然而,无论是RM -f RESULTS.TXT后运行什么测试时,它在生成文件中,它总是会产生一个错误。
Now I am able to run all of the above commands in this or any other order (provided the results.txt file exists for the appends) without problem. However, no matter what test is run after rm -f results.txt when it is in the makefile, it will always generate an error.
flip1 ~/src/dominion-base 161% make all
rm -f results.txt
cardtest1 > results1.txt
make: *** [runtests] Error 1
我一直在摆弄了一个小时(原本为所有,但>>意识到追加显然不创建一个不存在的文件),我真的不能确定究竟是什么错我的makefile
I have been tinkering with it for an hour (originally had all as >> but realized that an append apparently does not create a file that doesn't exist), and I am really unsure of what exactly is wrong with my makefile.
推荐答案
错误:
make: *** [runtests] Error 1
意味着,虽然make以构建目标 runtests
,其中一个命令,它跑了的错误code退出1
。在POSIX(并),任何退出$ C $ 0比其他C被认为是失败的;只有0意味着命令成功。
means that while make was building the target runtests
, one of the commands that it ran exited with an error code of 1
. In POSIX (and make), any exit code other than 0 is considered a failure; only 0 means that the command succeeded.
所以要会对其进行检查调用(这是它去的唯一的事情),如果它不是0它假定命令失败,并停止构建程序的退出code
So make will examine the exit code of the program it invokes (which is the only thing it has to go on) and if it's not 0 it assumes the command failed, and it stops the build.
在上面的我会说,你的程序 cardtest1
与1。退出code退出您可以通过运行(从你的shell命令行测试这个):
In the above I would say that your program cardtest1
is exiting with an exit code of 1. You can test this by running (from your shell command line):
cardtest1
echo $?
因为shell把刚刚完成的程序的退出code到shell变量 $?
。如果不是0,那么你需要修改 cardtest1
计划,以确保出口code设置正确。
because the shell puts the exit code of the just-completed program into the shell variable $?
. If it's not 0, then you need to modify your cardtest1
program to ensure that the exit code is set properly.
这篇关于在控制台正常工作的Makefile错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!