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论坛上找到了这篇文章,只需要按照这些步骤,它就适合我了。我在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设置

当使用交叉编译器时,我经常得到同事精心设计的高级自定义构建系统。我使用“现有代码的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子菜单中使用该命令获取解析器日志,可以提供非常丰富的信息。

Eclipse CDT 4.4 Luna和4.5 Mars的说明

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

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

在标题为“命令获取编译器规格”的文本框中添加-std=c++11

现在你可以创建项目,配置取决于你创建的项目类型:

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

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

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

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

对于CMake项目

生成eclipse项目文件(在项目内部)

mkdir build
cd build
cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ..

然后将生成的目录作为标准eclipse项目导入eclipse。右键单击项目并打开

属性-> C/ c++通用->预处理器包括路径,Marcos等->提供程序

启用CDT GCC内置编译器设置,并将其移动到贡献路径入口容器之上(这很重要)

最后常用步骤

重新编译,重新生成Project ->C/ c++索引并重新启动Eclipse。

我不知道是不是只有我,排名最高的解决方案不适合我,我的eclipse版本只是在Ubuntu中使用sudo apt-get install eclipse安装的普通eclipse平台 但是我发现了一个解决方案,它采用了从排名最高的解决方案和第二个解决方案一起的方法,我所做的工作如下所述(注意,为了简单起见,其他步骤如创建c++项目等被忽略)

创建了c++项目之后

(1) C/ c++通用->路径和符号->符号-> GNU c++。点击“Add…”,将GXX_EXPERIMENTAL_CXX0X(确保在“Name”中添加和前置两个下划线)粘贴到“Name”中,“Value”为空。

(2)在C/ c++ Build(在项目设置中)下,找到Preprocessor Include路径并进入Providers选项卡。取消选择除CDT GCC内置编译器设置外的所有设置。然后取消标记共享设置条目... .在名为Command的文本框中添加选项-std=c++11以获取编译器规格

在执行以上2和2个步骤后,它工作了,eclipse能够解决unique_ptr,我不知道为什么这个解决方案工作,希望它能帮助到人们。

对于最新的(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