Eclipse C++:无法解析符号“std”

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

Eclipse C++: Symbol 'std' could not be resolved

c++eclipseeclipse-cdt

提问by LCJ

I am getting this error in the TestExecute.cpp -

我在 TestExecute.cpp 中收到此错误 -

"Symbol 'std' could not be resolved"

“符号‘std’无法解析”

CODE

代码

#include <iostream>
using namespace std;

I just created a executable project in Eclipse (in Windows 7) as shown below. It seems like I am selecting a toolchain that is not supported. Is it so? I have installed Cygwin and it is available in preferences.

我刚刚在 Eclipse(在 Windows 7 中)中创建了一个可执行项目,如下所示。似乎我选择了不受支持的工具链。是这样吗?我已经安装了 Cygwin,它可以在首选项中使用。

EDIT: Based on @RobertoWilko comment, removing the line "using namespace std; " removed the error. But the binary is not created. "Launch Failed. Binary not found". How to correct this?

编辑:基于@RobertoWilko 评论,删除“使用命名空间 std;”行删除了错误。但是没有创建二进制文件。“启动失败。找不到二进制文件”。如何纠正这个?

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by user3729779

Try out this step: https://www.eclipse.org/forums/index.php/t/636348/

试试这一步:https: //www.eclipse.org/forums/index.php/t/636348/

Go to

Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers

Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers

  • Activate CDT GCC Built-in Compiler Settings
  • Deactivate Use global provider shared between projects
  • Add the command line argument -std=c++11.
  • 激活 CDT GCC 内置编译器设置
  • 停用使用项目之间共享的全局提供程序
  • 添加命令行参数 -std=c++11。

example

例子

回答by Frank

I do not know whether you have solved this problem but I want to post my solution for those might ran into the same problem.

我不知道你是否已经解决了这个问题,但我想发布我的解决方案,因为那些可能会遇到同样的问题。

  1. First, make sure that you have the "Includes" folder in your Project Explorer. If you do not have it, go to second step. If you have it, go to third step.

  2. Second, Window -> Preferences-> C/C++- > Build >Environment: Create two environment variables:

    a) Name: C_INCLUDE_PATHValue: /usr/include

    b) Name: CPLUS_INCLUDE_PATHValue: /usr/include/c++

  1. 首先,确保您的项目资源管理器中有“Includes”文件夹。如果没有,请转到第二步。如果有,请转到第三步。

  2. 二、Window -> Preferences-> C/C++-> Build >Environment:创建两个环境变量:

    a) 名称:C_INCLUDE_PATH值:/usr/include

    b) 名称:CPLUS_INCLUDE_PATH值:/usr/include/c++

Go to Cygwin/usr/include/, if you cannot find folder "c++", copy it from \cygwin\lib\gcc\i686-pc-cygwin\X.X.X\includeand Then restart your Eclipse.

转到Cygwin/usr/include/,如果找不到文件夹“c++”,请复制它\cygwin\lib\gcc\i686-pc-cygwin\X.X.X\include,然后重新启动 Eclipse。

  1. Third, Right Click your project in Project Explorer -> Properties -> C/C++ General -> Paths and Symbols -> Includes -> Languages:GNU C++If you can find some C++ folders in the "Include directories" then click Apply and OK. Change a bit your codes, and save it.
  1. 第三,在项目资源管理器中右键单击您的项目-> 属性 -> C/C++ 常规 -> 路径和符号 -> 包含 -> 语言:GNU C++如果您可以在“包含目录”中找到一些 C++ 文件夹,则单击应用并确定. 稍微更改一下您的代码,然后保存。

You will find there will be not symbol could not be resolved problems.

你会发现不会有符号无法解决的问题。

I documented my solution, hoping someone might get benefits.

我记录了我的解决方案,希望有人能从中受益。

回答by Myst

For MinGW this worked for me:

对于 MinGW 这对我有用:

  • Right click project, select Properties
  • Go to C/C++ General- Paths and Symbols- Includes- GNU C++- Include directories
  • Select Add...
  • Select Variables...
  • Select MINGW_HOMEand click OK
  • Click Applyand OK
  • 右键项目,选择 Properties
  • 前往C/C++ General- Paths and Symbols- Includes- GNU C++-Include directories
  • 选择 Add...
  • 选择 Variables...
  • 选择MINGW_HOME并点击OK
  • 单击ApplyOK

You should now see several MinGW paths in Includes in your project explorer.
The errors may not disappear instantly, you may need to refresh/build your project.

您现在应该在项目资源管理器的 Includes 中看到几个 MinGW 路径。
错误可能不会立即消失,您可能需要刷新/构建您的项目。



If you are using Cygwin, there could be an equivalent variable present.

如果您使用的是 Cygwin,则可能存在等效变量。

回答by liuzixing

You can rewrite the code likes this:

你可以像这样重写代码:

#include<iostream>
#include<stdio.h>

using namespace std;

回答by Meera Patil

The includes folder in the project is probably missing /usr/include/c++. Goto your project in project explorer, right click -> Properties -> C\C++ Build -> Environment -> add -> value= /usr/include/c++. Restart eclipse.

项目中的includes文件夹可能缺少/usr/include/c++。在项目资源管理器中转到您的项目,右键单击 -> 属性 -> C\C++ Build -> 环境 -> 添加 -> value= /usr/include/c++。重启日食。

回答by Malcolm Boyd

What allowed me to fix the problem was going to: Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers -> CDT GCC built-in compiler settings, enabling that and disabling the CDT Cross GCC Built-in Compiler Settings

让我解决问题的是:项目 -> 属性 -> C/C++ 常规 -> 预处理器包括路径、宏等 -> 提供程序 -> CDT GCC 内置编译器设置,启用并禁用 CDT跨 GCC 内置编译器设置

回答by Alaa M.

Install C++ SDK:

安装C++ SDK

Help > Install New Software > Work with: path for your eclipse version> search for C++and install C++ sdk development tools.

帮助 > 安装新软件 > 使用:path for your eclipse version> 搜索C++并安装 C++ sdk 开发工具。

Example for a path: Mars - http://download.eclipse.org/releases/mars

路径示例: Mars - http://download.eclipse.org/releases/mars

回答by Col_Parity

I was having this problem using Eclipse Neon on Kubuntu with a 16.04 kernel, I had to change my #include <stdlib.h>to #include <cstdlib>this made the std namespace "visible" to Eclipse and removed the error.

我在带有 16.04 内核的 Kubuntu 上使用 Eclipse Neon 时遇到了这个问题,我不得不将我的更改#include <stdlib.h>#include <cstdlib>这使得 std 命名空间对 Eclipse“可见”并消除了错误。

回答by Santiago Villafuerte

This worked for me on Eclipse IDE for C/C++ Developers Version: 2020-03 (4.15.0) Build id: 20200313-1211. Also, my code is cross-compiled.

这对我在 Eclipse IDE for C/C++ Developers Version: 2020-03 (4.15.0) Build id: 20200313-1211 上有用。另外,我的代码是交叉编译的。

  1. Create a new project making sure it's created as a cross-compiled solution. You have to add the /usr/bin directory that matches your cross-compiler location.
  2. Add the C and C++ headers for the cross-compiler in the Project Properties.
  3. For C: Project > Properties > C/C++ General > Paths and Symbols > Includes > GNU C. Add... -> The path to your /usr/include directory from your cross-compiler.
  4. For C++: Project > Properties > C/C++ General > Paths and Symbols > Includes > GNU C++. Add... -> The path to your /usr/include/c++/ directory from your cross-compiler.
  5. If you don't know your gcc version, type this in a console (make sure it's your cross gcc binary):

    gcc -v

  6. Modify the dialect for the cross-compilers (this was the trick).

  7. For C: Project > Properties > C/C++ Build > Settings > Tool Settings > Cross GCC Compiler > Dialect. Set to ISO C99 (-std=C99) or whatever fits your C files standard.
  8. For C++: Project > Properties > C/C++ Build > Settings > Tool Settings > Cross G++ Compiler > Dialect. Set to ISO C++14 (-std=c++14) or whatever fits your C++ files standard.
  9. If needed, re-index all your project by right-clicking the project > Index > Rebuild.
  1. 创建一个新项目,确保它是作为交叉编译的解决方案创建的。您必须添加与您的交叉编译器位置匹配的 /usr/bin 目录。
  2. 在项目属性中为交叉编译器添加 C 和 C++ 头文件。
  3. 对于 C:Project > Properties > C/C++ General > Paths and Symbols > Includes > GNU C. Add... -> 从你的交叉编译器到你的 /usr/include 目录的路径。
  4. 对于 C++:项目 > 属性 > C/C++ 常规 > 路径和符号 > 包含 > GNU C++。添加... -> 从交叉编译器到 /usr/include/c++/ 目录的路径。
  5. 如果您不知道您的 gcc 版本,请在控制台中输入以下内容(确保它是您的跨 gcc 二进制文件):

    gcc -v

  6. 修改交叉编译器的方言(这是诀窍)。

  7. 对于 C:项目 > 属性 > C/C++ 构建 > 设置 > 工具设置 > 跨 GCC 编译器 > 方言。设置为 ISO C99 (-std=C99) 或任何适合您的 C 文件标准的内容。
  8. 对于 C++:项目 > 属性 > C/C++ 构建 > 设置 > 工具设置 > 跨 G++ 编译器 > 方言。设置为 ISO C++14 (-std=c++14) 或任何适合您的 C++ 文件标准的内容。
  9. 如果需要,通过右键单击项目 > 索引 > 重建来重新索引所有项目。

回答by federico

The problem you are reporting seems to me caused by the following:

您报告的问题在我看来是由以下原因引起的:

  1. you are trying to compile C code and the source file has .cpp extension
  2. you are trying to compile C++ code and the source file has .c extension
  1. 您正在尝试编译 C 代码并且源文件具有 .cpp 扩展名
  2. 您正在尝试编译 C++ 代码并且源文件具有 .c 扩展名

In such situation Eclipse cannot recognize the proper compiler to use.

在这种情况下,Eclipse 无法识别要使用的正确编译器。