简体   繁体   English

Eclipse CDT C ++错误

[英]Eclipse CDT C++ error

I have just installed Eclipse CDT on my machine for developping C++ applications. 我刚刚在我的机器上安装了Eclipse CDT来开发C ++应用程序。

I have created a new C++ project. 我创建了一个新的C ++项目。 I have copied a cpp file. 我复制了一个cpp文件。

When I click the build button, the project compile without errors. 当我单击构建按钮时,项目编译没有错误。

However, I have a problem. 但是,我有一个问题。 The problem is that Eclipse tell me that there is many errors. 问题是Eclipse告诉我有很多错误。 For example Eclipse show that "using namespace std" is an error or that "#include " is an error. 例如,Eclipse显示“using namespace std”是一个错误,或者“#include”是一个错误。

I don't know what is the problem with Eclipse because my file compile properly when i click the "build" button. 我不知道Eclipse有什么问题,因为当我点击“构建”按钮时我的文件编译正确。

Is there some settings that I did not set properly? 是否有一些我没有正确设置的设置?

Thanks! 谢谢!

You need to add the paths to the std libraries to your project in eclipse. 您需要在eclipse中将std库的路径添加到项目中。 It seems that somehow eclipse did not find your std library. 似乎eclipse没有找到你的std库。 You need to add the path to your gcc include under: 您需要在以下位置添加gcc包含的路径:

properties->C/C++ General->Paths and Symbols->Includes->GNU C and GNU C++ properties-> C / C ++ General-> Paths and Symbols-> Includes-> GNU C和GNU C ++

The paths GCC/G++ uses can be found by the commands in this answer to "Where does gcc look for C and C++ header files?" GCC / G ++使用的路径可以通过这个答案中的命令找到: “gcc在哪里查找C和C ++头文件?” .

使用以下命令安装GNU C ++编译器g++

sudo apt-get install g++

In my case (I am using TDM GCC installed on a non-standard location on Windows), I had to add the Path variable to the project. 在我的情况下(我使用安装在Windows上的非标准位置的TDM GCC),我不得不将Path变量添加到项目中。 I did it by Project->Properties->C/C++ build->build variables. 我通过Project-> Properties-> C / C ++ build-> build variables做到了。 The value to the Path variables are auto read when one clicks on add and then select Path from the drop down list. 单击“添加”后,将自动读取“路径”变量的值,然后从下拉列表中选择“路径”。 Once the Path variable is added the C/C++ index needs to be rebuild. 添加Path变量后,需要重建C / C ++索引。

需要重启eclipse才能激活。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM