2013-07-09 38 views
2

我正在嘗試使用C++ 11,但eclipse遇到了一些麻煩。我使用macports來獲取gcc48,並且我遵循了各種使用新編譯器的指南,包括this,this, ,並且我也將編譯器命令從eclipse標準更改爲g ++ - mp- 4.8作爲解釋hereEclipse,Macos 10.8和C++ 11

我想建立以下程序:

#include <iostream> 
#include<memory> 
using namespace std; 
int main() { 
std::unique_ptr<double> ptr(new double); 
*ptr = 11.345; 

cout << (*ptr) << endl; 

return 0; 
} 

終端將編譯這個罰款,

make all 
Building file: ../src/C++11.cpp 
Invoking: Cross G++ Compiler 
/opt/local/bin/g++ -I/opt/local/bin -I/opt/local/include -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"src/C++11.d" -MT"src/C++11.d" -o "src/C++11.o" "../src/C++11.cpp" 
Finished building: ../src/C++11.cpp 

Building target: C++11 
Invoking: Cross G++ Linker 
g++ -o "C++11" ./src/C++11.o 
Finished building target: C++11 

,並在程序運行時只爲exp ected。但是在eclipse中,我仍然收到錯誤信息Symbol 'unique_ptr' could not be resolved

我想繼續使用eclipse作爲不僅僅是一個項目經理和生成文件生成器,所以任何幫助,將不勝感激!

回答

3

與其使用g ++,可以使用clang ++。我用的答案Error when compiling some simple c++ codeclang 3.1 can't see unique_ptr?How to compile a C++0x code on Eclipse CDT on mac?作爲指導來與以下步驟:

  1. 改變編譯器在項目 - >屬性 - > C/C++編譯 - >設置 - >的gcc C++編譯器 - >命令(將g ++更改爲clang ++)。

  2. in Project-> Properties-> C/C++ Build - > Settings - > Gcc C++ Compiler - > Miscellaneous,將-std=c++11 -stdlib=libc++附加到標誌。 >設置 - - >的gcc C++鏈接器 - >命令

  3. 在屬性 -

    > C/C++編譯 - >設置 - >的gcc C++鏈接器

  4. 下C/C的接頭++生成做同樣爲一個 - > Miscellaneous,將-stdlib=libc++添加到鏈接器標誌。

  5. in Properties-> C/C++ General - > Preprocessor Include Paths,Macros等 - > Providers - > CDT GCC內建編譯器設置,關閉Share選項,並將-std=c++11附加到Command以獲取編譯器規格。

編譯完美,程序運行良好。該日食不認識智能指針似乎是一個錯誤:請參閱Turn off eclipse errors (that arent really errors)