c++ - 为什么这个命令失败? rm 和 g++ 命令?

标签 c++ linux shell

rm *.o | g++ -c test.cpp | g++ test.o main.cpp

结果:

rm: cannot remove '*.o': No such file or directory
g++: error: test.o: No such file or directory

为什么?

最佳答案

两个问题:(a) 您可能没有任何要删除的 .o 文件,以及 (b) 您不恰本地使用了管道。尝试:

rm *.o &> /dev/null ; g++ -c test.cpp && g++ test.o main.cpp
       ^^^^^^^^^^^^^^                 ^^
       ignore any error               only try to link if
       message and                    compile is successful
       continue regardless

关于c++ - 为什么这个命令失败? rm 和 g++ 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43317878/

相关文章:

c++ - 如何在 C/C++ 中使用 WinHTTP 下载文件?

c++ - 使用 CMake ExternalProject 的目标名称以实现跨平台库依赖

c++ - 在我的例子中是指针还是值?

linux - 用户重新启动后自动启动不起作用

regex - 具有一个或多个 1234 实例但没有其他数字的行的 egrep 命令?

C: shell 流水线困惑

python - 如何分发由外部命令执行的代码? bash 脚本?

c++ - 有没有简单的方法来检查一个值是否不能安全地由另一种类型呈现?

python - 从脚本 python 获取变量环境的变化

linux - 了解涉及 pthread 时的 Linux 调度