[英]Eclipse CDT: Symbol 'cout' could not be resolved
The error is as above. 错误如上。 I have what should be all the necessary files include in the eclipse project:
我应该在Eclipse项目中包含所有必需的文件:
/usr/include/c++/4.6
/usr/include
/usr/include/linux
/usr/local/include
etc. 等等
I tried std::cout
and using namespace std;
我尝试了
std::cout
并using namespace std;
cout
but it still says unresolved. cout
但仍未解决。
I have imported iostream
and cstdlib
. 我已经导入了
iostream
和cstdlib
。
Also, I'm on Ubuntu 12.04 with eclipse 3.7.2. 另外,我在使用eclipse 3.7.2的Ubuntu 12.04。
Code snippet: 程式码片段:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "XPLMDisplay.h"
#include "XPLMGraphics.h"
int XPluginStart(char * outName, char * outSig, char * outDesc) {
/* ... */
std::cout << "test" << std::endl;
/* ... */
}
using namespace std; 使用命名空间std;
UPDATE: I had created the eclipse project from existing code. 更新:我已经从现有代码创建了eclipse项目。 Creating a new c++ project fixes it.
创建一个新的c ++项目即可对其进行修复。 I'll accept an answer that explains what setting in the existing project could cause this (so I don't have to cut & paste all my projects).
我将接受一个答案,该答案解释了现有项目中的哪些设置可能导致此问题(因此,我不必剪切并粘贴所有项目)。
Most likely you have some system-specific include directories missing in your settings which makes it impossible for indexer to correctly parse iostream, thus the errors. 很可能您的设置中缺少一些特定于系统的包含目录,这使索引器无法正确解析iostream,从而导致错误。 Selecting
Index -> Search For Unresolved Includes
in the context menu of the project will give you the list of unresolved includes which you can search in /usr/include
and add containing directories to C++ Include Paths and Symbols
in Project Properties. 在项目的上下文菜单中选择“
Index -> Search For Unresolved Includes
”将为您提供未解析的包含的列表,您可以在/usr/include
进行搜索并将包含目录添加到C++ Include Paths and Symbols
项目属性”中的C++ Include Paths and Symbols
。
On my system I had to add /usr/include/c++/4.6/x86_64-linux-gnu
for bits/c++config.h
to be resolved and a few more directories. 在我的系统上,我必须添加
/usr/include/c++/4.6/x86_64-linux-gnu
来解析bits/c++config.h
和更多目录。
Don't forget to rebuild the index (Index -> Rebuild) after adding include directories. 添加包含目录后,不要忘记重建索引(索引->重建)。
To get rid of symbol warnings you don't want, first you should understand how Eclipse CDT normally comes up with unknown symbol warnings in the first place. 为了摆脱不想要的符号警告,首先您应该了解Eclipse CDT通常如何首先产生未知的符号警告。 This is its process, more or less:
这是其过程,或多或少:
It might be better in the long run to fix problems with the earlier steps rather than to override their results by manually adding include directories, symbols, etc. 从长远来看,最好解决早期步骤中的问题,而不是通过手动添加包含目录,符号等来覆盖其结果。
Toolchains 工具链
If you have GCC installed, and Eclipse has detected it, it should list that GCC as a toolchain choice that a new C++ project could use, which will also show up in Window -> Preferences -> C/C++ -> New CDT Project Wizard
on the Preferred Toolchains
tab's Toolchains
box on the right side. 如果您已安装GCC,并且Eclipse已检测到它,则应将GCC列为新C ++项目可以使用的工具链选择,这还将显示在
Window -> Preferences -> C/C++ -> New CDT Project Wizard
在右侧的“ Preferred Toolchains
选项卡的“ Toolchains
框中。 If it's not showing up, see the CDT FAQ's answer about compilers that need special environments (as well as MinGW and Cygwin answers for the Windows folk.) 如果未显示,请参阅CDT常见问题解答中有关需要特殊环境的编译器的答案 (以及Windows 人群的MinGW和Cygwin答案)。
If you have an existing Eclipse C++ project, you can change the associated toolchain by opening the project properties, and going to C/C++ Build -> Tool Chain Editor
and choosing the toolchain you want from the Current toolchain:
pulldown. 如果您有现有的Eclipse C ++项目,则可以通过打开项目属性,然后转到
C/C++ Build -> Tool Chain Editor
并从Current toolchain:
下拉菜单中选择所需的工具链,来更改关联的工具Current toolchain:
。 (You'll have to uncheck the Display compatible toolchains only
box first if the toolchain you want is different enough from the one that was previously set in the project.) (如果所需的工具链与项目中先前设置的工具链有足够不同,则必须首先取消选中“
Display compatible toolchains only
框。)
If you added a toolchain to the system after launching Eclipse, you will need to restart it for it to detect the toolchain. 如果在启动Eclipse之后将工具链添加到系统,则需要重新启动它以检测工具链。
Discovery 发现
Then, if the project's C/C++ Build -> Discovery Options -> Discovery profiles scope
is set to Per Language
, during the next build the new toolchain associated with the project will be used for auto-discovery of include paths and symbols, and will be used to update the "built-in" paths and symbols that show up in the project's C/C++ General -> Paths and Symbols
in the Includes
and Symbols
tabs. 然后,如果项目的
C/C++ Build -> Discovery Options -> Discovery profiles scope
设置为Per Language
,则在下一次构建期间,与该项目关联的新工具链将用于自动发现包含路径和符号,并将用于更新“内置”路径和符号,这些路径和符号显示在项目的C/C++ General -> Paths and Symbols
Includes
和“ Symbols
选项卡中的C/C++ General -> Paths and Symbols
中。
Indexing 索引编制
Sometimes you need to re-index again after setting the toolchain and doing a build to get the old symbol warnings to go away; 有时,您需要在设置工具链并进行构建以使旧的符号警告消失后再重新索引。 right-click on the project folder and go to
Index -> Rebuild
to do it. 右键单击项目文件夹,然后转到
Index -> Rebuild
。
(tested with Eclipse 3.7.2 / CDT 8) (已在Eclipse 3.7.2 / CDT 8中进行了测试)
Thanks loads for the answers above. 感谢负载为上面的答案。 I'm adding an answer for a specific use-case...
我正在为特定用例添加答案...
On a project with two target architectures each with its own build configuration (the main target is an embedded AVR platform; the second target is my local Linux PC for running unit tests) I found it necessary to set Preferences -> C/C++ -> Indexer -> Use active build configuration
as well as to add /usr/include/c++/4.7
, /usr/include
and /usr/include/c++/4.7/x86_64-linux-gnu
to Project Properties -> C/C++ General -> Paths and Symbols
and then to rebuild the index. 在一个具有两个目标体系结构的项目中,每个目标体系结构都有自己的构建配置(主要目标是嵌入式AVR平台;第二个目标是用于运行单元测试的本地Linux PC),我发现有必要设置
Preferences -> C/C++ -> Indexer -> Use active build configuration
,以及将/usr/include/c++/4.7
/usr/include
和/usr/include/c++/4.7/x86_64-linux-gnu
到Project Properties -> C/C++ General -> Paths and Symbols
,然后重建索引。
I tried the marked solution here first. 我首先在这里尝试了标记的解决方案。 It worked but it is kind hacky, and you need to redo it every time you update the gcc.
它可以工作,但是有点hacky,并且每次更新gcc时都需要重做。 I finally find a better solution by doing the followings:
通过执行以下操作,我终于找到了更好的解决方案:
Project
-> Properties
-> C/C++ General
-> Preprocessor Include Paths, Macros, etc.
Project
-> Properties
-> C/C++ General
-> Preprocessor Include Paths, Macros, etc.
Providers
-> CDT GCC built-in compiler settings
Providers
-> CDT GCC built-in compiler settings
Use global provider shared between projects
(you can also modify the global provider if it fits your need) Use global provider shared between projects
的全局提供程序(如果需要,您也可以修改全局提供程序) Command to get compiler specs
, add -std=c++11
at the end Command to get compiler specs
,在末尾添加-std=c++11
Index
-> Rebuild
Index
-> Rebuild
Voila, easy and simple. 瞧,简单容易。 Hopefully this helps.
希望这会有所帮助。
Note: I am on Kepler. 注意:我在开普勒。 I am not sure if this works on earlier Eclipse.
我不确定这是否适用于早期的Eclipse。
I am using Ubuntu 12.04 / Eclipse 4.2.1 / CDT 8.1.1 and I used to have the same problem for quite some time: importing a C++ project from SVN would cause these annoying "Unresolved inclusion" errors and I would instead have to create a new project and copy the files in there as a work-around (still partial, since SVN functionality would not be there!). 我正在使用Ubuntu 12.04 / Eclipse 4.2.1 / CDT 8.1.1,并且在相当长的一段时间里我曾经遇到过相同的问题:从SVN导入C ++项目将导致这些令人讨厌的“无法解决的包含”错误,而我不得不创建一个新项目,并在其中复制文件作为解决方法(由于SVN功能不存在,因此仍是部分文件!)。
At last, I have just found a simple, satisfactory solution: 最后,我找到了一个简单而令人满意的解决方案:
Go to Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers
and check Enable language settings providers for this project
. 转到
Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers
并选中Enable language settings providers for this project
。
Restart Eclipse. 重新启动Eclipse。
Hopefully that already does the trick. 希望那已经成功了。
I had a similar problem with *std::shared_ptr* with Eclipse using MinGW and gcc 4.8.1. 使用MinGW和gcc 4.8.1的Eclipse在* std :: shared_ptr *上遇到了类似的问题。 No matter what, Eclipse would not resolve *shared_ptr*.
无论如何,Eclipse都不会解析* shared_ptr *。 To fix this, I manually added the __cplusplus macro to the C++ symbols and - viola!
为了解决这个问题,我手动将__cplusplus宏添加到C ++符号中,并且-中提琴! - Eclipse can find it.
-Eclipse可以找到它。 Since I specified -std=c++11 as a compile option, I (ahem) assumed that the Eclipse code analyzer would use that option as well.
因为我将-std = c ++ 11指定为编译选项,所以我(哼)假定Eclipse代码分析器也将使用该选项。 So, to fix this:
因此,要解决此问题:
The only problem with this is that gcc will complain that the symbol is already defined(!) but the compile will complete as before. 唯一的问题是gcc会抱怨该符号已经定义(!),但是编译将像以前一样完成。
对我而言,它有助于启用“属性”->“ C / C ++-Build”->“发现选项”中的自动发现来解决此问题。
I simply delete all error in the buttom: problem list. 我只是删除buttom:问题列表中的所有错误。 then close project and reopen project clean project build all run
然后关闭项目并重新打开项目,清理项目,使所有运行正常
then those stupids errors go. 然后那些愚蠢的错误就消失了。
If all else fails, like it did in my case, then just disable annotations. 如果所有其他方法都失败了(就像我的情况一样),请禁用注释。 I started a c++11 project with own makefile but couldn't fix all the problems.
我用自己的makefile开始了一个c ++ 11项目,但无法解决所有问题。 Even if you disable annotations, eclipse will still be able to help you do some autocompletion.
即使禁用注释,eclipse仍然可以帮助您进行自动补全。 Most importantly, the debugger still works!
最重要的是,调试器仍然可以运行!
I had the same issue using Eclipse CDT (Kepler)
on Windows
with Cygwin
installed. 在装有
Cygwin
Windows
上使用Eclipse CDT (Kepler)
,我遇到了同样的问题。 After pointing the project properties at every Cygwin include I could think of, it still couldn't find cout
. 在我想到的每个Cygwin都指向了项目属性之后,仍然找不到
cout
。
The final missing piece turned out to be C:cygwin64\\lib\\gcc\\x86_64-pc-cygwin\\4.8.2\\install-tool\\include
. 最后遗失的部分是
C:cygwin64\\lib\\gcc\\x86_64-pc-cygwin\\4.8.2\\install-tool\\include
。
To sum up: 总结一下:
Properties
Properties
C/C++ General
> Paths and Symbols
> Includes
tab C/C++ General
> Paths and Symbols
> Includes
选项卡 Add...
Add...
File system...
File system...
lib\\gcc\\x86_64-pc-cygwin\\4.8.2\\install-tool\\include
lib\\gcc\\x86_64-pc-cygwin\\4.8.2\\install-tool\\include
OK
OK
Here is what my project includes ended up looking like when it was all said and done: 这是我的项目所包含的最终一切都说完之后的样子:
You guys are looking under the wrong section. 你们正在寻找错误的部分。 I realized the difference when I installed in Linux after recently getting frustrated with Windows and the difference was immediately apparent.
在最近对Windows感到沮丧之后,当我在Linux中安装时,我意识到了这种区别,并且这种区别立即显而易见。
In the new setup I have an includes folder in a projected that I created out of existing source. 在新设置中,我有一个投影文件夹,该投影文件夹是根据现有资源创建的。 I can expand this and see a ton of includes;
我可以扩展它并看到大量的包含; however, I cannot add to them.
但是,我不能添加它们。 This lead me to a hunt for where these files were being listed.
这使我开始寻找这些文件的列出位置。
They're listed under the Project Properties > C/C++ General > Preprocessor Includes > GNU C++ CDT GCC Built-in Compiler Settings [Shared] Under that is a ton of includes. 它们在“项目属性”>“ C / C ++常规”>“预处理程序包含”>“ GNU C ++ CDT GCC内置编译器设置”下列出。
These settings are set by the toolchain you've selected. 这些设置由您选择的工具链设置。
I have created the Makefile project using cmake on Ubuntu 16.04. 我已经在Ubuntu 16.04上使用cmake创建了Makefile项目。
When created the eclipse project for the Makefiles which cmake generated I created the new project like so: 为cmake生成的Makefile创建eclipse项目时,我创建了一个新项目,如下所示:
File --> new --> Makefile project with existing code. 文件->新建->使用现有代码的Makefile项目。
Only after couple of times doing that I have noticed that the default setting for the "Toolchain for indexer settings" is none. 只有经过几次,我才注意到“用于索引器设置的工具链”的默认设置为none。 In my case I have changed it to Linux GCC and all the errors disappeared.
就我而言,我将其更改为Linux GCC,所有错误均消失了。
Hope it helps and let me know if it is not a legit solution. 希望它会有所帮助,让我知道这是否不是一个合法的解决方案。
Cheers, 干杯,
Guy. 伙计
Just adding yet another bit of advice after trying a bunch of stuff myself and it not working.... 自己尝试了一堆东西之后又添加了一些建议,但它不起作用。
I had GCC installed and the path to the includes set correctly. 我已经安装了GCC,并且正确设置了包含路径。 Had the std error as well, and couldn't get anything working for cout (and I suspect anything in the SL...)
也有std错误,并且无法为cout工作(我怀疑SL中有任何东西...)
Took me awhile to realize that g++ wasn't installed - gcc was but not g++. 花了我一段时间才意识到未安装g ++-gcc已安装但未安装g ++。 So just do:
所以做:
sudo apt-get install g++ 须藤apt-get install g ++
Restart eclipse. 重新开始蚀。 Assuming above mentioned details about gcc & paths to includes are fine, you should be okay now...
假设上面提到的有关gcc和包含路径的详细信息很好,那么您现在应该可以...
I had this happen after updating gcc and eclipse on ArchLinux. 我在ArchLinux上更新gcc和eclipse之后发生了这种情况。 What solved it for me was
Project -> C/C++ Index -> Rebuild
. 为我解决的是
Project -> C/C++ Index -> Rebuild
。
mine was bit easy to fig out right click >run as>run configration 我的有点容易找出右键单击>运行方式>运行配置
check boxes include system lib,inherited mains 复选框包括系统库,继承的主电源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.