【问题标题】:Eclipse, Macos 10.8 and C++11Eclipse、Macos 10.8 和 C++11
【发布时间】:2013-07-10 20:44:25
【问题描述】:

我正在尝试使用 C++11,但 eclipse 遇到了一些问题。我使用 macports 来获取 gcc48,并遵循各种指南让 eclipse 使用新编译器,包括this、this、 而且我还将编译器命令从 eclipse 标准更改为 g++-mp-4.8,如 here

所述

我正在尝试构建以下程序:

#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

程序按预期运行。但是,在eclipse中,我仍然收到错误消息Symbol 'unique_ptr' could not be resolved。

我希望继续使用 eclipse,而不仅仅是项目经理和 makefile 构建器,因此我们将不胜感激!

【问题讨论】:

    标签: eclipse macos c++11


    【解决方案1】:

    可以使用clang++,而不是使用g++。我以Error when compiling some simple c++ code、clang 3.1 can't see unique_ptr? 和How to compile a C++0x code on Eclipse CDT on mac? 的答案为指导,提出了以下步骤:

    1. 在Project->Properties->C/C++ Build -> Settings -> Gcc C++ Compiler -> Command中更改编译器(将g++改为clang++)。

    2. 在 Project->Properties->C/C++ Build -> Settings -> Gcc C++ Compiler -> Miscellaneous,将 -std=c++11 -stdlib=libc++ 附加到标志。

    3. 对C/C++ Build -> Settings -> Gcc C++ Linker -> Command 下的链接器做同样的操作

    4. 在 Properties->C/C++ Build -> Settings -> Gcc C++ Linker -> Miscellaneous 中,将 -stdlib=libc++ 添加到 Linker 标志中。

    5. 在Properties->C/C++ General -> Preprocessor Include Paths, Macros,etc -> Providers -> CDT GCC Builtin Compiler Settings,关闭Share选项,在Command后面追加-std=c++11即可编译器规范。

    编译完美,程序运行良好。那个 Eclipse 不能识别智能指针似乎是一个错误:见Turn off eclipse errors (that arent really errors)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      • 2012-08-08
      • 2018-05-27
      • 1970-01-01
      • 2023-03-04
      相关资源
      最近更新 更多