Eclipse 3.7.1 CDT 1.4.1 GCC 4.6.2

下面是c++ 11代码的一个例子:

auto text = std::unique_ptr<char[]>(new char[len]);

Eclipse编辑器抱怨:

Function 'unique_ptr' could not be resolved

Makefile编译工作正常。如何让Eclipse停止抱怨这类错误?


当前回答

我在Eclipse论坛上找到了这篇文章,只需要按照这些步骤,它就适合我了。我在Windows上使用Cygwin设置的Eclipse Indigo 20110615-0604。

Make a new C++ project Default options for everything Once created, right-click the project and go to "Properties" C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put -std=c++0x (or for newer compiler version -std=c++11 at the end . ... instead of GCC C++ Compiler I have also Cygwin compiler C/C++ General -> Paths and Symbols -> Symbols -> GNU C++. Click "Add..." and paste __GXX_EXPERIMENTAL_CXX0X__ (ensure to append and prepend two underscores) into "Name" and leave "Value" blank. Hit Apply, do whatever it asks you to do, then hit OK.

现在在Eclipse FAQ/ c++ 11 Features中也有关于这方面的描述。

Eclipse设置

其他回答

要在Eclipse Luna中获得对c++ 14的支持,您可以执行以下步骤:

在c++ General ->预处理器Include -> Providers -> CDT Cross GCC内置编译器设置中,添加"-std=c++14" 在c++ Build -> Settings -> Cross g++ Compiler -> Miscellaneous中,添加"-std=c++14"

重新索引项目并最终重新启动Eclipse。它应该像预期的那样工作。

对于我来说,我在Eclipse Neon上遵循了上面的Trismegistos的答案,然而我还添加了一个额外的步骤:

转到项目——>属性——> c++通用——>预处理器包括路径,宏等——>提供者——> CDT跨GCC内置编译器设置,附加标志"-std=c++11"

点击应用并确定。

欢呼,

Guy.

我在Mac上用这种方法解决了这个问题。我用Homebrew安装了最新版本的gcc/g++。它们落在/usr/local/bin中,包含在/usr/local/include中。

我CD到/usr/local/bin,做了一个符号链接,从g++@7whatever到g++,因为@位很烦人。

然后我打开MyProject -> Properties -> C/ c++ Build -> Settings -> GCC c++ Compiler并将命令从“g++”更改为“/usr/local/bin/g++”。如果您决定不使用符号链接,则可以更具体。

对链接器执行相同的操作。

应用,应用,关闭。让它重新构建索引。有一段时间,它显示了大量的错误,但我认为那是在建立索引时。当我找出错误时,它们都消失了,没有进一步的操作。


我认为在没有验证的情况下,你也可以进入Eclipse ->属性-> C/ c++ ->核心构建工具链,并编辑那些具有不同路径的工具链,但我不确定这将做什么。

Eclipse C/ c++不识别符号std::unique_ptr,即使您在文件中包含了c++ 11内存头文件。

假设你正在使用GNU c++编译器,这是我所做的修复:

项目->属性-> C/ c++通用->预处理器包括路径-> GNU c++ -> CDT用户设置条目

点击“Add…”按钮 从下拉菜单中选择“预处理宏” 名称:__cplusplus值:201103L 点击Apply,然后OK回到你的项目 然后重建你的c++索引:Projects -> C/ c++索引->重建

当使用交叉编译器时,我经常得到同事精心设计的高级自定义构建系统。我使用“现有代码的Makefile项目”,所以大多数其他答案都不适用。

At the start of the project, I have to specify that I'm using a cross compiler in the wizard for "Makefile Project with Existing Code". The annoying thing is that in the last 10 or so years, the cross compiler button on that wizard doesn't prompt for where the cross compiler is. So in a step that fixes the C++ problem and the cross compiler problem, I have to go to the providers tab as mentioned by answers like @ravwojdyla above, but the provider I have to select is the cross-compiler provider. Then in the command box I put the full path to the compiler and I add -std=gnu++11 for the C++ standard I want to have support for. This works out as well as can be expected.

您可以对现有项目执行此操作。您可能需要做的唯一一件事就是重新运行索引器。

我从未需要添加experimental标志或重写__cplusplus的定义。 唯一的问题是,如果我有大量的现代C代码,我就无法放置特定于C的标准选项。

当情况非常糟糕时,在Indexer子菜单中使用该命令获取解析器日志,可以提供非常丰富的信息。