我正在尝试执行我的第一个“Hello World!” 在 C++ 中。我使用的是 Windows XP,并且我已经安装了 cygwin,其中安装了 g++ C++ 编译器。我写了一个小 hello-world 程序,并保存在 hello.cpp 中。从命令提示符我写:
g++你好.cpp
但我得到:
'g++' 不是内部或外部命令、可运行程序或批处理文件。
我已经在我的 D:\programs\cygwin 中安装了 cygwin。我在 D:\cpp 中用我的 hello-world 文件创建了另一个目录。我的安装或路径似乎不太好,但我不知道是什么。我已经运行了 cygwin 的 exe 文件,并且在安装目录中我得到了所有必要的文件,我认为:bin 文件夹、lib、Cygwin.bat 等。
我已经阅读过,如果出现此类错误消息,我应该检查 cygwin1.dll 文件是否已复制到 Windows 的主文件夹中。这是 C:\WINDOWS 目录吗?我看过那里,我那里没有这样的文件。我在cygwin的bin文件夹中有cygwin1.dll:D:\programs\cygwin\bin。另外,如何检查命令的搜索路径中是否考虑了 bin 文件夹(D:\programs\cygwin\bin)?
我认为 hello-world 程序不应该包含任何语法错误,我只是复制了它。另外,当我写
g++ -v
我收到相同的错误消息:该命令无法识别。如果有人给我提示我应该看什么,我将不胜感激。谢谢你。
下面是 hello-world 程序的代码:
#include <iostream>
using namespace std;
int main() {
cout <<"Hello World!"<<endl;
return 0;
}
我已经安装了 g++,现在当我输入 g++ -v 时,我得到:Reading specs from: \d\cygnus\cygwin-b20\H-i586-cygwin32\bin..\lib\gcc-lib\i586-cygwin32\ egcs-2.91.57\specs gcc 版本 egcs-2.91.57 19980901(egcs-1.1 版本)
在 bin 目录中,我有 g++.exe 和 gcc.exe。我不明白为什么我在上面得到“gcc”而不是“g++”。我不知道这有多重要,但是当我尝试在 DOS 命令提示符下编译程序时收到错误消息:
g++你好.cpp
我得到:
hello.cpp:1: parse error before character 0357
hello.cpp: In function 'int main()':
hello.cpp:'cout' undeclared (first use this function)
hello.cpp: (Each undeclared identifier is reported only once
hello.cpp: for each function it appears in.)
hello.cpp: 'endl' undeclared (first use this function)
这是我尝试在 cygwin shell 中编译程序时得到的结果:
hello.cpp:1: parse error before character 0357
hello.cpp: In function 'int main()':
hello.cpp:'cout' undeclared (first use this function)
hello.cpp: (Each undeclared identifier is reported only once
hello.cpp: for each function it appears in.)
hello.cpp: 'endl' undeclared (first use this function)
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files