Makefile:
foo.o: foo.cpp
g++ -o foo.o foo.cpp
foo.cpp:
aslkfdj
输出:
$ g++ -o foo.o foo.cpp; echo $?
foo.cpp:1:1: error: ‘aslkfdj’ does not name a type
aslkfdj
^
1
$ make; echo $?
g++ -o foo.o foo.cpp
foo.cpp:1:1: error: ‘aslkfdj’ does not name a type
aslkfdj
^
Makefile:2: recipe for target 'foo.o' failed
make: *** [foo.o] Error 1
0
$
从make中我期望得到退出码2,因为g++返回了非零值,参见。
$ man make|grep exits -A2
GNU make exits with a status of zero if all makefiles were successfully parsed and no targets that were built failed. A sta‐
tus of one will be returned if the -q flag was used and make determines that a target needs to be rebuilt. A status of two
will be returned if any errors were encountered.
我哪里做错了?
值得一提的是,我在Xubuntu 15.10上也遇到了相同的退出代码:
$ make --version
GNU Make 4.0
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
就像在某些旧的OS X服务器上一样:
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin10.0
\make -f; \echo $?
会打印什么内容(请注意前导反斜杠和故意无效的参数)。 - skyking