简体   繁体   English

我怎样才能回应编译的状态?

[英]How can I echo the status of compilation?

I've written a small command to compile every C file in every directory , I have: 我写了一个小命令来编译每个目录中的每个C文件,我有:

find $1 -type f -name '*.c' -exec sh -c 'gcc  {} -o $(dirname {})/$(basename {} .c)' \;

and it compiles everything, but I would like it to display the status of each file being compiled, and display when each one is finished, but I'm really out if ideas. 并且它编译了所有内容,但是我希望它能够显示正在编译的每个文件的状态,并在每个文件完成时显示,但是如果想法的话,我真的很好。

If anyone could help I would love that! 如果有人可以帮助我会喜欢!

You can echo $? 你可以echo $? after running gcc which will show you its return status. 运行gcc后会显示其返回状态。 If a file compiles it will be 0 , if it doesn't it will be 1 I think. 如果一个文件编译它将是0 ,如果不编译它将是1我认为。 But there may be different return values for different errors, I'm not sure about this. 但是对于不同的错误可能会有不同的返回值,我对此不太确定。

This is likely an academic issue, but using {} multiple times in the argument to find is not portable. 这可能是一个学术问题,但在find的参数中多次使用{}是不可移植的。 Similarly, expecting {} to expand to the filename when it is not the only string in the argument is not portable. 同样,当它不是参数中唯一的字符串时,期望{}扩展为文件名是不可移植的。 (That is, the entire argument must be exactly {} ). (也就是说,整个论证必须完全是{} )。 Also, using gcc explicitly rather than make is probably the wrong approach. 此外,明确使用gcc而不是make可能是错误的方法。 That said, you can simply echo each path that successfully compiles: 也就是说,您可以简单地回显成功编译的每个路径:

find $1 -type f -name '*.c' -exec sh -c 'gcc $0 -o $(dirname $0)/$(basename $0.c) &&
    echo $0' {} \;

Also, if you can simplify with bash: 另外,如果你可以用bash简化:

find $1 -type f -name '*.c' -exec bash -c 'gcc $0 -o ${0%.c}.o && echo $0' {} \;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM