简体   繁体   English

CLion无法解析类型std :: unordered_map,即使它提示我包括标头并且编译工作

[英]CLion cannot resolve type std::unordered_map even though it prompted me to include the header and the compilation works

For some reason my CLion cannot recognize std::unordered_map even though it actually suggested me to include the header by Alt+Enter when I first wrote out the type definition. 由于某种原因,我的CLion无法识别std::unordered_map ,尽管它实际上建议我在首次写出类型定义时通过Alt+Enter包含标头。 After I included the header by #include <unordered_map> , the compilation works as well. 在通过#include <unordered_map>包含标头之后,编译也将正常进行。

I can even Ctrl+Click on the include line to find the header file, but I can't click on the line of type definition (which keeps remaining red). 我什至可以Ctrl +单击include行以查找头文件,但不能单击类型定义行(保持红色)。 I don't understand why the IDE keeps refusing to recognize the type within the code. 我不明白为什么IDE一直拒绝识别代码中的类型。

Actually, it then suggests me to include bits/unordered_map.h . 实际上,它然后建议我包括bits/unordered_map.h I can find unodered_map.h in both /usr/include/c++/7.3.1/unordered_map and /usr/include/c++/7.3.1/bits/unordered_map.h . 我可以在/usr/include/c++/7.3.1/unordered_map/usr/include/c++/7.3.1/bits/unordered_map.h找到unodered_map.h I'm not sure what's the difference between these two. 我不确定这两者之间有什么区别。 Including either or both doesn't solve the problem. 包括其中一个或两个都不能解决问题。

I added -std=c++11 to CMAKE_CXX_FLAGS in my CMakeLists.txt already. 我已经在CMakeLists.txt CMAKE_CXX_FLAGS -std=c++11添加到CMAKE_CXX_FLAGS中。

CLion 2018.1, gcc 7.3.1, Arch Linux. CLion 2018.1,gcc 7.3.1,Arch Linux。

Bad news: it's CLion issue . 坏消息:这是CLion 问题

Good news: it was fixed. 好消息:它是固定的。 Please try using CLion 2018.1.1 EAP. 请尝试使用CLion 2018.1.1 EAP。 The issue should be fixed in it. 该问题应该得到解决。

Here is the related problem . 这是相关的问题

I don't know about CLion but in Eclipse Luna with TDM-GCC as compiler these errors are usually caused because the project isn't built . 我不了解CLion,但是在带有TDM-GCC作为编译器的Eclipse Luna中,这些错误通常是由于未构建项目引起的。 Also verify that unordered_map is indeed in the /include folder of your project . 还要验证unordered_map确实在项目的/ include文件夹中。 You can also include higher std flags like -std=c++14 . 您还可以包括更高的std标志,例如-std = c ++ 14

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM