红联Linux门户
Linux帮助

解决linux eclipse c++找不到符号或者~~~name a type的问题

发布时间:2016-04-24 10:25:37来源:linux网站作者:oiooooio

首先我的环境是:

centos 6.5

eclipse c++ 官网下载

gcc4.8.2


我的问题的出现是因为c++11的新的一些功能如:

std::function

std::bind

这些符号找不到。


下面是我的解决办法(注意往下看):

首先解决方式是参照:

There's two things you have to do, first you need to setup your compiler, then you need to setup CDT's language processor. Since you didn't mention which compiler you're using, I'll assume it's GCC but the steps will be similar for other compilers. (Note that you need a compiler that supports C++11, of course.)

Setting up the compiler is fairly straightforward:

1.Right click your project and click Properties
2.Under C/C++ Build click Settings
3.Under GCC C++ Compiler, click Miscellaneous
4.In the Other Flags box, append "-std=c++11" to the list of tokens.
5.Click Apply and OK

At this point you should be able to rebuild your project and get it to run. But CDT still may show errors for C++11 includes. Here's how you can resolve that:

1.Right click your project and click Properties
2.Under C/C++ General click "Preprocessor Include Paths, Macros"
3.Select the Providers tab
4.There should be an item in the list that says something like "GCC Built in Compiler Settings". Select this entry.
5.Uncheck the "Use global provider..." option
6.Under the list there's an box that says "Command to get compiler specs." Append "-std=c++0x" to this.
7.Move the "GCC Built in Compiler Settings" provider at the top of the list using the 'Move Up' button on the right.
8.Click Apply and then OK.
9.Back in your Eclipse workspace, select the Project Menu, C/C++ Index, and click "Re-resolve unresolved includes."


这是上面的解决方案。这个方法基本上解决了问题。但是对于我来说,只解决了一半问题,因为按照上面的方法修改后,问题依旧,怎么办呢?


下来是我的方法。

解决linux eclipse c++找不到符号或者~~~name a type的问题

alt+enter->c/c++ general->path and symbols->symbols tab->GNU C++

找到上图的位置,,注意这个位置是:项目-属性,你可以点击项目后,按alt+enter打开。

1、选择GNU C++, 

2、点击右边的add,

3、然后在name那个输入框里随便输入,你没有看错,随便输入后,点击ok确定,

4、然后点击下方的apply,会弹出一个对话框,选择yes。这个对话框估计就是目的所在。

5、然后删除刚刚添加的项。

6、重复4

7、Back in your Eclipse workspace, select the Project Menu, C/C++ Index, and click "Re-resolve unresolved includes."

上面我的方法是无意中发现的。

至少对我的问题是有效的。希望能解决你的问题。


本文永久更新地址:http://www.linuxdiyf.com/linux/20033.html