我创建了一个文件,1.sh,作为
c++ -c file1.cpp
c++ file1.o -o file1
我尝试在 Windows 上的 bash Ubuntu 上执行它。它告诉我
: No such file or directory
c++: fatal error: no input files
compilation terminated.
但是,如果我执行
c++ -c file1.cpp
c++ file1.o -o file1
直接编译文件(file1.cpp)即可正常编译。
我的问题是,.sh 文件不起作用的原因是什么以及如何修复它?
最佳答案
其实,我想把它写成评论,但没有这种格式可用。 (当这个答案过时时,我会删除它。)
我刚刚尝试了这个(在 cygwin 的 bash 上使用 g++):
$ g++ -c nothing.cc
g++: error: nothing.cc: No such file or directory
g++: fatal error: no input files
compilation terminated.
$
当然,在我当前的工作目录中没有文件nothing.cc
...
所以,我的猜测(从 shell 脚本启动时 C++ 在错误的工作目录中运行)可能是合理的...
正如我已经建议的那样:插入一个
echo "$PWD"
确保在您的 shell 脚本的开头。
更新:
出于好奇,我也尝试了这个(再次是 cygwin,bash):
$ c++ -c nothing.cc
c++: error: nothing.cc: No such file or directory
c++: fatal error: no input files
compilation terminated.
$
现在,它看起来与 OP 非常相似。
唯一让我困惑的事实是:OP 的错误信息看起来像是编译器是否没有得到任何输入:
$ c++
c++: fatal error: no input files
compilation terminated.
$
但我相信情况并非如此,因为在 OP 中它以
开头
: 没有那个文件或目录
。
因此,它看起来像是缺少一些文本......
关于c++ - 在windows上的ubuntu中执行.sh文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43970526/