最初の「Hello World!」を実行しようとしています。C++で。Windows XP を使用しており、g++ C++ コンパイラがインストールされている cygwin をインストールしました。小さな 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 フォルダー (D:\programs\cygwin\bin) に cygwin1.dll があります。また、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 と入力すると、次のように表示されます。 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 シェルでプログラムをコンパイルしようとすると、次のようになります。
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