【发布时间】:2011-11-12 11:53:31
【问题描述】:
我的计算机上安装了 MinGW(我只使用 Strawberry perl 附带的那个)。我可以从命令行很好地编译东西。然而,使用 Eclipse CDT 会导致奇怪的错误。使用 Eclipse 自带的 c++ hello world 默认项目,在 CDT 中编译失败并出现以下错误:
\**** Internal Builder is used for build \****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hw.o ..\src\hw.cpp
..\src\hw.cpp:9:20: error: iostream: No such file or directory
..\src\hw.cpp: In function 'int main()':
..\src\hw.cpp:13: error: 'cout' was not declared in this scope
..\src\hw.cpp:13: error: 'endl' was not declared in this scope
Build error occurred, build is stopped
Time consumed: 263 ms.
但是,当我在命令行上运行 g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hw.o ..\src\hw.cpp 时,编译一切正常。所有正确的头文件(如 iostream)都在我的路径变量中。我需要更改哪些 Eclipse 设置才能使其正常工作?
这是我要编译的文件:
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
【问题讨论】:
-
你记得
#include <iostream>吗? -
转到您项目的属性,导航到
C\C++ General > Paths and Symbols > Includes (tab)并选择GNU C++语言。您是否看到一堆通往 MinGW 安装的路径?另外,您能否发布您尝试编译的代码(简化版本)。最后你设置了 MINGW_HOME 环境变量吗?
标签: c++ compiler-errors mingw eclipse-cdt