解決linux eclipse c++找不到符號或者~~~name a type的問題 && c++11

首先我的環境是:

centos 6.5

eclipse c++ 官網下載

gcc4.8.2



---

ok!

我的問題的出現是因爲c++11的新的一些功能如:

std::function

std::bind

這些符號找不到。


---

下面是我的解決辦法(注意往下看):

首先我的解決方式是參照:http://stackoverflow.com/questions/17457069/enabling-c11-in-eclipse-juno-kepler-luna-cdt這個帖子解決的,尊重原創。

如果你打不開這個鏈接,那麼答案如下:

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."
這是上面鏈接的帖子的解決方案。



---

這個方法基本上解決了問題。但是對於我來說,只解決了一半問題,因爲按照上面的方法修改後,問題依舊,怎麼辦呢,下來是我的方法。

---


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."

上面我的方法是無意中發現的。

至少對我的問題是有效的。希望能解決你的問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章