c++ - 在windows上的ubuntu中执行.sh文件

标签 c++ bash shell ubuntu windows-subsystem-for-linux

我创建了一个文件,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/

相关文章:

c++ - 在源文件中定义数组并在其他源文件中使用它

c++ - 如何推断模板中的数组类型?

c++ - 从字符串中删除一些字符并复制它

node.js - 自动同步本地 Github 存储库与服务器上的目录

linux - 在 SSH 中使用本地和远程变量

shell - 从字符串中删除第一个字符

php - 使用 PHP 执行 unix shell 命令

c++ - Qt-用图像填充圆圈

linux - 如何将 stderr 重定向到一个文件并将一些回显(不是 stdout)重定向到同一个文件

bash - 转义单引号 ssh 远程命令