Eclipse CDT 索引器不知道 C++11 容器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17131744/
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-09-10 21:45:15  来源:igfitidea点击:

Eclipse CDT indexer does not know C++11 containers

eclipsec++11buildindexer

提问by clstaudt

I configured a C++11 project in Eclipse CDT to use gcc-4.7. It is not the default compiler on my system, which does not support C++11. In order for compilation to work, I need to pass the flag -std=c++11and also include the following header path: /usr/local/Cellar/gcc/4.7.2/gcc/include/c++/4.7.2

我在 Eclipse CDT 中配置了一个 C++11 项目以使用 gcc-4.7。它不是我系统上的默认编译器,它不支持 C++11。为了使编译正常工作,我需要传递标志-std=c++11并包含以下标头路径:/usr/local/Cellar/gcc/4.7.2/gcc/include/c++/4.7.2

Whenever I use C++11 container types like std::unordered_setor std::unordered_map, the CDT indexer complains: Symbol unordered_set could not be resolved. How can I tell the indexer to resolve these symbols correctly?

每当我使用 C++11 容器类型(如std::unordered_set或 )时std::unordered_map,CDT 索引器都会抱怨:Symbol unordered_set could not be resolved. 如何告诉索引器正确解析这些符号?

This is how I have configured my indexer:

这是我配置索引器的方式:

enter image description here

在此处输入图片说明

As far as I understand the settings, the indexer is supposed to use the compiler settings from the currently active build configuration. Compilation works fine, so why doesn't indexing, too?

据我了解设置,索引器应该使用当前活动构建配置中的编译器设置。编译工作正常,那么为什么不索引呢?

采纳答案by user2485710

As described in this forum post:

如本论坛帖子所述:

http://www.eclipse.org/forums/index.php/mv/msg/282618/

http://www.eclipse.org/forums/index.php/mv/msg/282618/

  • right-click the project and go to "Properties" C/C++ General -> Paths and Symbols -> Symbols -> GNU C++.
  • Click "Add..." and paste __GXX_EXPERIMENTAL_CXX0X__into "Name" and leave "Value" blank. Hit Apply, do whatever it asks you to do, then hit OK.
  • 右键单击项目并转到“属性”C/C++ 常规 -> 路径和符号 -> 符号 -> GNU C++。
  • 单击“添加...”并粘贴__GXX_EXPERIMENTAL_CXX0X__到“名称”中,并将“值”留空。点击应用,做任何它要求你做的事情,然后点击确定。

回答by selyunin

Setting up **__GXX_EXPERIMENTAL_CXX0X__**does not help in my case (Jul 2014, Eclipse Kepler 20130919, Ubuntu 12.04).

设置**__GXX_EXPERIMENTAL_CXX0X__**对我来说没有帮助(2014 年 7 月,Eclipse Kepler 20130919,Ubuntu 12.04)。

To fix C++11 syntax highlighting go to:

要修复 C++11 语法高亮,请转到:

Project Properties --> C/C++ General --> Paths and Symbols --> Symbols --> GNU C++

项目属性 --> C/C++ 常规 --> 路径和符号 --> 符号 --> GNU C++

and overwrite the symbol (i.e. add new symbol):

并覆盖符号(即添加新符号):

__cplusplus

with value

有价值

201103L

UPDATED:If you use newer version of Eclispe (as of 2016) and still experience the same problem, try value (as pointed by jose.diego):

更新:如果您使用较新版本的 Eclispe(截至 2016 年)并且仍然遇到同样的问题,请尝试 value(如 jose.diego 所指出的):

201402L

Make sure that indexer is enabled in Project settings (C/C++ general --> Indexer)

确保在项目设置中启用索引器(C/C++ 常规 --> 索引器

Then reindex (Project --> C/C++ Index --> Rebuild)

然后重新索引(项目 --> C/C++ 索引 --> 重建

if the problem still persist reindex once again. It should work now.

如果问题仍然存在,请再次重新索引。它现在应该可以工作了。

回答by Galik

I solved this problem recently after some lucky googling.

我最近在一些幸运的谷歌搜索后解决了这个问题。

Click on your project and right-click->Properties

单击您的项目并右键单击-> 属性

Select"C/C++ General ->Processor Include Paths, Macros etc..."

选择“C/C++ General ->Processor Include Paths, Macros etc...”

Selectthe "Providers" tab

选择“提供者”选项卡

Deselecteverything except"CDT User Setting Entries" and "CDT GCC Built-in Compiler Settings"

取消一切除了“CDT用户设置项”和“CDT GCC内置的编译器设置”

Click on"CDT GCC Built-in Compiler Settings"

点击“CDT GCC内置编译器设置”

Deselect"Use global provider shared between projects"

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

Editthe box at the bottom labeled "Command to get compiler specs"

编辑底部标有“获取编译器规范的命令”的框

Insertinto the command -std=c++11 so it looks something like this:

插入命令 -std=c++11 使其看起来像这样:

${COMMAND} -std=c++11 -E -P -v -dD "${INPUTS}"

ClickApply and Okay.

单击应用和确定。

enter image description here

在此处输入图片说明

That worked for me. You probably need to re-index the project.

那对我有用。您可能需要重新索引项目。

回答by user1283078

Or go to:

或前往:

  • C/C++ Build->Discovery Options->GCC C++ Compiler

  • add your flags to the Compiler invocation arguments. like -std=c++11 -m32

  • Clear discovered entrys now: click on Clear

  • rebuild the project

  • C/C++ Build->Discovery Options->GCC C++ Compiler

  • 将您的标志添加到编译器调用参数。像 -std=c++11 -m32

  • 立即清除发现的条目:单击清除

  • 重建项目

After that ALL symbols will be updated with correct values and the indexer should work as intended

之后,所有符号都将使用正确的值进行更新,索引器应按预期工作

回答by Afilu

The workaround for me, with a project that uses an external builder, was to define the symbol:

对于使用外部构建器的项目,我的解决方法是定义符号:

__cplusplus

__cplusplus

with the value:

值:

201403

201403

in the project's: Paths and Symbols -> Symbols/GNU C++.

在项目的:路径和符号 -> 符号/GNU C++。

This worked in eclipse Kepler CDT Version: 8.3.0.201402142303.

这在 eclipse Kepler CDT 版本:8.3.0.201402142303 中有效。

回答by Yojiaku

See this guide:

请参阅本指南

  1. C/C++ Build->Settings->GCC C++ Compiler->Dialect
  2. Choose "ISO C++11 (-std=c++0x)" in "language standard" Language and dialect
  3. Apply and OK
  4. Rebuild the project and it works:)
  1. C/C++ Build->Settings->GCC C++ Compiler->Dialect
  2. 在“语言标准”中选择“ISO C++11 (-std=c++0x)” 语言和方言
  3. 申请并确定
  4. 重建项目,它的工作原理:)

回答by caot

The follows works in EclipseC/C++Oxygen.2 with gcc-5.5.0

以下适用于EclipseC/C++Oxygen.2 与gcc-5.5.0

Eclipse Properties->C/C++ Build->Settings->GCC C++ Compiler->Dialect->Other dialect flags: -std=c++17

Eclipse Properties->C/C++ Build->Settings->GCC C++ Compiler->Dialect->Other dialect flags: -std=c++17

Don't pick up anything in the Language standarddropdown list.

不要在Language standard下拉列表中选择任何内容。

回答by q0987

The following configuration helps me to fix the issue indicated in the original question.

以下配置可帮助我解决原始问题中指出的问题。

Environment: Eclipse(Oxygen.3a Release (4.7.3a)), Cygwin64. In case you have a different version of Cygwin, you can find similar directories as follows.

环境:Eclipse(Oxygen.3a Release (4.7.3a)),Cygwin64。如果您有不同版本的 Cygwin,您可以找到类似的目录,如下所示。

Step 1: Make sure you have the following two directories:

第 1 步:确保您有以下两个目录:

   C:\cygwin64\lib\gcc\x86_64-pc-cygwin.4.0\include
   C:\cygwin64\lib\gcc\x86_64-pc-cygwin.4.0\include\c++

If you don't see the above two directories, please launch your Cygwin setup program and install gcc-core, gcc-g++ and libgcc1.

如果您没有看到以上两个目录,请启动您的 Cygwin 安装程序并安装 gcc-core、gcc-g++ 和 libgcc1。

Step 2: Copy the directory C:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\includeto C:\cygwin64\usrif you don't see above two include directories.

第二步:如果你没有看到上面两个包含目录C:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\includeC:\cygwin64\usr则将目录复制到。

Step 3: Go to Project Property->C/C++ General->Paths and Symbols Make sure you can see the following two paths are listed

步骤 3:转到 Project Property->C/C++ General->Paths and Symbols 确保您可以看到列出了以下两个路径

   C:\cygwin64\usr\include
   C:\cygwin64\usr\include\c++

Step 4: Property->C/C++ Build/Settings/ Choose Cygwin PE Parser

第 4 步:Property->C/C++ Build/Settings/选择 Cygwin PE Parser

Step 5: Property->C/C++ Build/Tool Chain Editor Choose Cygwin GCC

第五步:Property->C/C++ Build/Tool Chain Editor 选择 Cygwin GCC

Step 6: Property->C/C++ General/Indexer Choose Enable indexer

第六步:Property->C/C++ General/Indexer 选择 Enable indexer

Step 7: Project->C/C++ Index->Rebuild

第七步:Project->C/C++ Index->​​Rebuild

Now your eclipse should be able to see the C++11 types.

现在您的 Eclipse 应该能够看到 C++11 类型。