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设置

其他回答

2016年更新:

从gcc 6开始(更改),默认的c++方言是c++ 14。这意味着,除非您明确地需要比than更新或更老的方言,否则您不需要再使用eclipse做任何事情了。

月球和火星

这个社区wiki部分包含了Trismegistos的答案;

1. 在创建项目之前,配置Eclipse语法解析器:

窗口->首选项-> C/ c++ ->构建->设置->发现-> CDT GCC内置编译器设置

在标题为“命令获取编译器规格”的文本框中添加-std=c++14 2. 创建项目,配置取决于你创建的项目类型:

对于创建为:File -> New -> project -> C/ c++ -> c++ project

右键单击创建的项目并打开

属性-> C/ c++构建->设置->工具设置-> GCC c++编译器->方言

将-std=c++14放入标题为“其他方言标志”的文本框中,或从“语言标准”下拉菜单中选择“ISO c++ 11”。

现在有一种新的方法来解决这个问题,而不需要GXX_EXPERIMENTAL黑客。

对于最新版本:(目前是朱诺和开普勒Luna):

在Juno的新版本下,设置位于项目属性-> C/ c++通用->预处理器包括路径,宏等->选项卡提供程序-> CDT GCC内置编译器设置()。

旧版本2012/2013:

在C/ c++ Build (at project settings)下,找到Preprocessor Include Path,然后转到Providers选项卡。取消选择除CDT GCC内置编译器设置外的所有设置。然后取消标记共享设置条目... .在名为Command的文本框中添加选项-std=c++11以获取编译器规格。 选择路径和符号。在符号下,单击恢复默认值,然后应用。


注:

Eclipse对点击apply很挑剔,每次离开设置选项卡时都需要这样做。

【自我推广】:在以上的基础上,我自己写了更详细的说明。 http://scrupulousabstractions.tumblr.com/post/36441490955/eclipse-mingw-builds

感谢https://stackoverflow.com/a/13635080/1149664的用户Nobody

我在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设置

我还不能评论,所以我写了我自己的答案:

它与__GXX_EXPERIMENTAL_CXX0X__相关,对Eclipse Juno和CDT 8.x有效。

这个答案的一些部分已经在其他答案中涵盖了,但我希望它是连贯的。

为了能够使用stdc++11构建,必须为编译器添加特定的标志。您可以通过项目属性来实现这一点。修改项目属性RMB和项目属性或ALT + ENTER。然后C/ c++构建->设置->工具设置-> GCC c++编译器-> Miscellaneous ->其他标志。将-std=c++11放在行末,对于GCC来说,它看起来像这样:-c -fmessage-length=0 -std=c++11。通过添加-stdc++11标志,编译器(GCC)将自己声明__GXX_EXPERIMENTAL_CXX0X__。

此时,您可以使用c++ 11的所有优点来构建项目。

The problem is that Eclipse has it's own parser to check for errors - that's why you're still getting all the nasty errors in Eclipse editor, while at the same time you can build and run project without any. There is a way to solve this problem by explicitly declaring __GXX_EXPERIMENTAL_CXX0X__ flag for the project, one can do that (just like Carsten Greiner said): C/C++ General -> Paths and Symbols -> Symbols -> GNU C++. Click "Add..." and past __GXX_EXPERIMENTAL_CXX0X__ (ensure to append and prepend two underscores) into "Name" and leave "Value" blank. And now is the extra part I wanted to cover in comment to the first answer, go to: C/C++ General -> Preprocessor Include Path Macros etc. -> Providers, and Select CDT Managed Build Setting Entries then click APPLY and go back to Entries tab, under GNU C++ there should be now CDT Managed Build Setting Entries check if inside there is defined __GXX_EXPERIMENTAL_CXX0X__ if it is -> APPLY and rebuild index you should be fine at this point.

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

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

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

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

对于最新的(Juno) eclipse cdt,以下对我有效,不需要对自己声明__GXX_EXPERIMENTAL_CXX0X__。这适用于CDT索引器和编译器的参数:

“您的项目名称”->右键单击->属性:

C/ c++通用->预处理器包括路径,宏等->切换到名为“提供商”的选项卡:

对于“配置”,选择“发布”(然后选择“调试”) 关闭所有提供程序,选择“CDT GCC内置编译器设置” 取消勾选“项目间共享设置条目(全局提供者)” 在"Command to get compiler specs:" add "-std=c++11"不带引号(也可以使用引号) 点击应用并关闭选项 重新构建索引

现在所有c++11相关的东西都应该被索引器正确地解析了。

Win7 x64,最新的官方eclipse与CDT 来自sourceforge上mingwbuilds项目的Mingw-w64 GCC 4.7.2