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 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 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 c++ 2019-03进行C和c++混合项目时遇到了类似的问题,该项目使用std::optional和std::swap。对我有用的是这个。
在项目中 属性->C/ c++构建->设置->工具设置->交叉g++编译器,从Miscellaneous中删除-std= gn++ 17,并将其放在Dialect->Other Dialect Flags中。
无论是hack版本还是更干净的版本都不能用于Indigo。黑客被忽略,所需的配置选项丢失。没有明显的原因,构建在不能工作后开始工作,并且没有提供任何有用的原因。至少从命令行,我得到了可重复的结果。
对于最新的(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
对于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++编译器->杂项->其他 对于开普勒来说,旗帜还不够,但对于较老的版本,如太阳神,它已经足够了。
当使用交叉编译器时,我经常得到同事精心设计的高级自定义构建系统。我使用“现有代码的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子菜单中使用该命令获取解析器日志,可以提供非常丰富的信息。