我试图在终端上运行一个基本的C ++文件:
#include <iostream>
using namespace std;
int main() {
cont << "This is my first C++ program!";
return 0
}
然后尝试在终端中运行它:
Kawika-and-Chloe-Boss:~ kawikaandchloe$ make learningCPP.cpp
make: *** No rule to make target `learningCPP.cpp'. Stop.
并尝试:
Kawika-and-Chloe-Boss:~ kawikaandchloe$ make learningCPP
make: *** No rule to make target `learningCPP'. Stop.
并尝试:
Kawika-and-Chloe-Boss:~ kawikaandchloe$ gcc learningCPP.cpp -o learningCPP.out
clang: error: no such file or directory: 'learningCPP.cpp'
clang: error: no input files
以下是整个bash / clang文件:
Last login: Mon May 25 07:49:21 on console
Kawika-and-Chloe-Boss:~ kawikaandchloe$ make learningCPP.cpp
make: *** No rule to make target `learningCPP.cpp'. Stop.
Kawika-and-Chloe-Boss:~ kawikaandchloe$ make learningCPP
make: *** No rule to make target `learningCPP'. Stop.
Kawika-and-Chloe-Boss:~ kawikaandchloe$ gcc learningCPP.cpp -o learningCPP.out
clang: error: no such file or directory: 'learningCPP.cpp'
clang: error: no input files
Kawika-and-Chloe-Boss:~ kawikaandchloe$ $ g++ -o lab21 learningCPP.cpp
-bash: $: command not found
Kawika-and-Chloe-Boss:~ kawikaandchloe$ $ ./lab21
-bash: $: command not found
Kawika-and-Chloe-Boss:~ kawikaandchloe$ ./learningCPP.cpp
-bash: ./learningCPP.cpp: No such file or directory
Kawika-and-Chloe-Boss:~ kawikaandchloe$ ./main
-bash: ./main: No such file or directory
Kawika-and-Chloe-Boss:~ kawikaandchloe$ $ g++ -o main learningCPP.cpp
-bash: $: command not found
Kawika-and-Chloe-Boss:~ kawikaandchloe$ cpp
make learningCPP.cpp
run
asdklajdl;jaksld
sadddasdfasddas
df
dsa
f
dsa
你能帮忙吗?
答案 0 :(得分:2)
根据错误判断,您的文件不会被称为learningCPP.cpp
,或者不在您尝试编译的目录中。
重命名它以使其具有该名称,或将目录更改为其位置,然后构建命令为
g++ learningCPP.cpp -o learningCPP
不是gcc
,并且没有假的$
。或者,只要源文件存在于工作目录中,您就可以使用make learningCPP
。
成功后,使用
运行程序./learningCPP
虽然您必须阅读新的错误消息,并在编译之前使用它来弄清楚如何修复语法错误。