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停止抱怨这类错误?


当前回答

无论是hack版本还是更干净的版本都不能用于Indigo。黑客被忽略,所需的配置选项丢失。没有明显的原因,构建在不能工作后开始工作,并且没有提供任何有用的原因。至少从命令行,我得到了可重复的结果。

其他回答

对于Eclipse CDT Kepler,我摆脱std::线程未解析符号的工作是:

进入“首选项->C/ c++ ->构建->设置” 选择Discovery选项卡 选择CDT GCC内置编译器设置[共享] 在“Command to get compiler specs:”字段中添加-std=c++11,例如:

${COMMAND} -E -P -v -dD -std=c++11 ${输入}

好的,然后重建项目的索引。

添加-std=c++11到项目属性/ c / c++构建->设置->工具设置->GCC c++编译器->杂项->其他 对于开普勒来说,旗帜还不够,但对于较老的版本,如太阳神,它已经足够了。

右键单击项目,选择“属性” C/ c++ Build -> Settings -> Tool Settings -> GCC c++ Compiler -> Miscellaneous -> Other Flags。将-lm放在其他标志文本框的末尾,然后确定。

我在使用Eclipse c++ 2019-03进行C和c++混合项目时遇到了类似的问题,该项目使用std::optional和std::swap。对我有用的是这个。

在项目中 属性->C/ c++构建->设置->工具设置->交叉g++编译器,从Miscellaneous中删除-std= gn++ 17,并将其放在Dialect->Other Dialect Flags中。

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

它与__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 Neon上遵循了上面的Trismegistos的答案,然而我还添加了一个额外的步骤:

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

点击应用并确定。

欢呼,

Guy.