Eclipse CDT 编译错误

发布于 2024-12-03 11:07:25 字数 950 浏览 1 评论 0原文

我的计算机上安装了 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;
}

I have MinGW installed on my computer (I just use the one shipped with Strawberry perl). I can compile things just fine from the command line. Using Eclipse CDT, however, results in weird errors. Using the c++ hello world default project which comes with Eclipse, compilation in CDT fails with these errors:

\**** 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.  

But when I run g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hw.o ..\src\hw.cpp on my command line compilation goes just fine. All of the proper header files (like iostream) are in my path variable. What eclipse settings do I need to change to make this work?

Here's the file I'm trying to compile:

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏至、离别 2024-12-10 11:07:25

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

I experienced this only a few days ago, the problem turned out to be that I had both g++4.3 and g++4.4 installed and Eclipse was getting confused. I uninstalled 4.3 and the problem went away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文