我的计算机上安装了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)都在我的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,问题消失了。

关于c++ - Eclipse CDT上的编译错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7340079/

10-14 16:56