【问题标题】:Compilation error on Eclipse CDTEclipse CDT 上的编译错误
【发布时间】: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 &lt;iostream&gt;吗?
  • 转到您项目的属性,导航到C\C++ General &gt; Paths and Symbols &gt; Includes (tab) 并选择GNU C++ 语言。您是否看到一堆通往 MinGW 安装的路径?另外,您能否发布您尝试编译的代码(简化版本)。最后你设置了 MINGW_HOME 环境变量吗?

标签: c++ compiler-errors mingw eclipse-cdt


【解决方案1】:

我几天前才经历过这种情况,问题原来是我同时安装了 g++4.3 和 g++4.4 并且 Eclipse 变得混乱。我卸载了 4.3,问题就消失了。

【讨论】:

    猜你喜欢
    • 2011-08-16
    • 1970-01-01
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 2011-12-19
    • 2011-01-18
    • 1970-01-01
    相关资源
    最近更新 更多