Eclipse CDT上的编译错误

Compilation error on Eclipse CDT

本文关键字:编译 错误 CDT Eclipse      更新时间:2023-10-16

我在我的计算机上安装了MinGW(我只是使用草莓perl附带的那个)。我可以很好地从命令行编译东西。然而,使用Eclipse CDT会导致奇怪的错误。使用Eclipse自带的c++ hello world默认项目,在CDT中编译失败,出现以下错误:

**** Internal Builder is used for build               ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrchw.o ..srchw.cpp
..srchw.cpp:9:20: error: iostream: No such file or directory
..srchw.cpp: In function 'int main()':
..srchw.cpp:13: error: 'cout' was not declared in this scope
..srchw.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 -osrchw.o ..srchw.cpp时,编译正常。所有适当的头文件(如iostream)都在我的path变量中。我需要更改哪些eclipse设置才能使其工作?

这是我要编译的文件:

#include <iostream>
using namespace std;
int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

我几天前才遇到这种情况,问题原来是我同时安装了g++4.3和g++4.4, Eclipse开始混淆了。我卸载了4.3,问题消失了。