C++ Eclipse 索引器无法解析 shared_ptr

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8312854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:21:17  来源:igfitidea点击:

Eclipse indexer can't resolve shared_ptr

c++eclipsec++11

提问by Dylan Klomparens

After researching this on the internet, I've been unable to get the Eclipse indexer to resolve "shared_ptr" from the C++0x additions that come with GCC 4.4.4. I made sure to create my project with the proper includes for Eclipse, so it's definitely looking in the the 4.4.4 include folders.

在 Internet 上对此进行研究后,我一直无法让 Eclipse 索引器从 GCC 4.4.4 附带的 C++0x 添加项中解析“shared_ptr”。我确保使用适当的 Eclipse 包含创建我的项目,因此它肯定会在 4.4.4 包含文件夹中查找。

The program compiles and runs just fine. To access shared_ptr I'm using "#include <memory>".

该程序编译并运行得很好。要访问 shared_ptr,我正在使用“#include <memory>”。

Any idea what's breaking the indexer?

知道是什么破坏了索引器吗?

回答by Dave S

You need to set the pre-processor symbol '__GXX_EXPERIMENTAL_CXX0X__' to the eclipse project. g++ automatically adds that when you use '-std=c++0x', but eclipse is not aware of that, so it treats those sections of the relevant headers as disabled.

您需要将预处理器符号 ' __GXX_EXPERIMENTAL_CXX0X__' 设置为 eclipse 项目。g++ 会在您使用“-std=c++0x”时自动添加,但 eclipse 不知道这一点,因此它将相关标题的那些部分视为已禁用。

回答by Dean Hill

I experienced this problem under Windows with Eclipse 4.5.1 (Mars.1) and Cygwin 2.3.0 (GCC 4.9.3).

我在使用 Eclipse 4.5.1 (Mars.1) 和 Cygwin 2.3.0 (GCC 4.9.3) 的 Windows 下遇到了这个问题。

The indexer can't find shared_ptr because of lines like this in the <memory> header. The __cplusplus macro is evaluating to something other than C++ 11 (aka 201103) so the older auto_ptr.h is being included instead of shared_ptr.h. Why? The below screen shot of the project properties shows that C++ 98 (199711) is being detected under CDT GCC Build-in Compiler Settings.

由于 <memory> 标头中的类似行,索引器无法找到 shared_ptr。__cplusplus 宏正在评估 C++ 11(又名 201103)以外的内容,因此包含较旧的 auto_ptr.h 而不是 shared_ptr.h。为什么?下面的项目属性屏幕截图显示在 CDT GCC 内置编译器设置下检测到 C++ 98 (199711)。

#if __cplusplus >= 201103L
#  include <bits/shared_ptr.h>
#else
#  include <backward/auto_ptr.h>
#endif

enter image description here

在此处输入图片说明

There are two possible solutions to tell Eclipse to use C++ :

有两种可能的解决方案告诉 Eclipse 使用 C++:

  • On the same Preprocessor Include Paths screen, scroll to the top of the Setting Entries area. Expand CDT User Setting Entries. Add a new Preprocessor Macro for __cplusplus=201103L. Do this for both the Release and Debug Configurations. Then rebuild the index.

  • If you want to default the CDT GCC Build-in Compiler Settings to use 201103 for all projects, then edit the language.settings.xml file (under Windows this is c:\Users\deanhill\workspace\.metadata\.plugins\org.eclipse.cdt.core\language.settings.xml). Set __cplusplus=201103L. Restart Eclipse and rebuild the index.

  • 在同一个 Preprocessor Include Paths 屏幕上,滚动到 Setting Entries 区域的顶部。展开 CDT 用户设置条目。为 __cplusplus=201103L 添加一个新的预处理器宏。为发布和调试配置执行此操作。然后重建索引。

  • 如果要默认 CDT GCC 内置编译器设置为所有项目使用 201103,请编辑 language.settings.xml 文件(在 Windows 下,这是 c:\Users\deanhill\workspace\.metadata\.plugins\org .eclipse.cdt.core\language.settings.xml)。设置 __cplusplus=201103L。重新启动 Eclipse 并重建索引。

回答by Makketronix

Although I am late to the game, this is what worked for me:

虽然我玩游戏迟到了,但这对我有用:

Right-Click on Project->Properties->C/C++ General->Preprocessor Include Paths, Macros, etc. --> Click "Providers" tab --> CDT GCC Built-in Compiler Settings

右键Project->Properties->C/C++ General->Preprocessor Include Paths、Macros等-->点击“Providers”选项卡--> CDT GCC Built-in Compiler Settings

Uncheck "Use global provider shared between projects"

取消选中“使用项目之间共享的全局提供程序”

Add -std=c++0x

添加 -std=c++0x

It will then look something like this:

然后它看起来像这样:

${COMMAND} ${FLAGS} -E -P -v -dD -std=c++0x "${INPUTS}"

Rebuild index.

重建索引。

Using Debian Jessie + Eclipse Kepler Build id: 20140224-0627

使用 Debian Jessie + Eclipse Kepler 构建 ID:20140224-0627

回答by da-na

I experienced the same problem. I have added the GXX_EXPERIMENTAL_CXX0Xas well as -std=c++11to compiler options in workspace. However it did not solve my problem.

我遇到了同样的问题。我在工作区中添加了GXX_EXPERIMENTAL_CXX0X以及-std=c++11编译器选项。然而它并没有解决我的问题。

I was missing one more step: Right-Click on Project->Properties->C/C++ Build->Settings->Cross G++ Compiler->Miscellaneous->Other flags I changed -c -fmessage-length=0to -c -fmessage-length=0 -std=c++11

我又错过了一个步骤:右键单击项目-> 属性-> C/C++ 构建-> 设置-> 交叉 G++ 编译器-> 杂项-> 我更改-c -fmessage-length=0为的 其他标志 -c -fmessage-length=0 -std=c++11

Now Eclipse sees std::shared_ptr and indexes it correctly.

现在 Eclipse 看到 std::shared_ptr 并正确索引它。

回答by Sarmo Fdmusik

For me it worked by setting other dialect flags = -std=c++11under:

对我来说,它通过设置other dialect flags = -std=c++11在:

Preferences -> C++ Build -> Settings -> GCC C++ Compiler -> Dialect,

首选项 -> C++ 构建 -> 设置 -> GCC C++ 编译器 -> 方言

as well as adding -std=c++11under:

以及在下面添加-std=c++11

Preferences -> C++ General -> Preprocessor Include Path -> Providers -> CDT GCC Build-in Compiler Settings -> command to get compiler specs.

Preferences -> C++ General -> Preprocessor Include Path -> Providers -> CDT GCC Build-in Compiler Settings -> command to get compiler specs

Do not forget to clean and rebuild your Project/Index.

不要忘记清理和重建您的项目/索引。