eclipse 类型 'uint32_t' 无法解析

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

Type 'uint32_t' could not be resolved

c++eclipsec++11gcceclipse-cdt

提问by ErikJL

I am working on a C++ program in Eclipse (3.8.1) CDT. I am using the gcc compiler on Debian 8. I'm also using an open source library called opendnp3 written in C++, which requires uint32_tto resolve as it's a parameter in several method calls and constructors.

我正在 Eclipse (3.8.1) CDT 中开发 C++ 程序。我在 Debian 8 上使用 gcc 编译器。我还使用了一个名为 opendnp3 的开源库,用 C++ 编写,它需要uint32_t来解析,因为它是几个方法调用和构造函数中的参数。

In the opendnp objects, intellisense doesnt list

在 opendnp 对象中,intellisense 没有列出

__uint32_thowever, DOES resolve.

__uint32_t但是,确实解决了。

The type is defined in <cstdint>(<cstdint>resolves just fine). I can open the declaration and clearly see 'using ::uint32_t;' in there.

类型定义在<cstdint>(<cstdint>解析得很好) 中。我可以打开声明并清楚地看到其中的“ using ::uint32_t;”。

In my searching, I've added -std=c++11to 'All options' under 'C/C++ Build --> Settings -> Tool Settings -> GCC C++ Compiler' and I've also rebuilt the project index and restarted Eclipse, but it still doesn't resolve.

在我的搜索中,我已经添加-std=c++11到“C/C++ Build --> Settings -> Tool Settings -> GCC C++ Compiler”下的“All options”,我还重建了项目索引并重新启动了 Eclipse,但它仍然没有不解决。

Here's the code so far: Edited to a simple HelloWorld project to help diagnose problem

到目前为止的代码如下:编辑为一个简单的 HelloWorld 项目以帮助诊断问题

#include <iostream>
#include <cstdint> //has uint32_t defined
using namespace std;

int main() {
    __uint32_t t = 0;  //resolves just fine
    uint32_t i = 0; //Type could not be resolved
    auto x = "123"; //C++ 11 working
    cout << "Foo!" << endl; // prints Foo!
    return 0;
}

CDT Console after a build attempt:

构建尝试后的 CDT 控制台:

23:10:52 **** Incremental Build of configuration Debug for project FOO **** make all make: Nothing to be done for 'all'.

23:10:52 **** 项目 FOO 的配置调试的增量构建 **** make all make:“所有”无需执行任何操作。

23:10:52 Build Finished (took 133ms)

23:10:52 构建完成(耗时 133 毫秒)

回答by davmac

I know this question is old, but I feel it's worth mentioning that I was having this exact problem and was able to resolve it just be rebuilding the index: right-click the project, "Index", "Rebuild". You said that you had rebuilt the index and it didn't help; importantly, I did this after adding -std=c++11to the command line for the compiler specified in the "CDT GCC Built-in Compiler Settings", which can be found by opening project properties and going to "C/C++ General", "Preprocessor Include Paths, Macros etc", "Providers" tab. You wouldn't, if I understand correctly, need to do this with GCC version 6+ as it defaults to C++14; I'm using GCC 5.4 myself.

我知道这个问题很老,但我觉得值得一提的是我遇到了这个确切的问题并且能够通过重建索引来解决它:右键单击项目,“索引”,“重建”。你说你重建了索引,但没有帮助;重要的是,我在添加-std=c++11到“CDT GCC 内置编译器设置”中指定的编译器的命令行后执行此操作,可以通过打开项目属性并转到“C/C++ 常规”、“预处理器包含路径”、宏等”,“提供程序”选项卡。如果我理解正确,您不需要使用 GCC 版本 6+ 来执行此操作,因为它默认为 C++14;我自己正在使用 GCC 5.4。

If that doesn't help, the best path for debugging the issue is probably to open the declaration for cstdint(the include file itself - so, right click cstdintwithin the #includedirective, and choose "open declaration") - this will show you the included file, with sections greyed out if they are precluded via preprocessor macros (#ifdefand the like). You may be able to see immediately why uint32_tis not considered defined. In my case, the __cplusplusmacro had an unsuitable value and this led me to adding -std=c++11to the compiler command line as mentioned above - butI still needed to rebuild the index before the problem was fully resolved.

如果这没有帮助,调试问题的最佳途径可能是打开声明cstdint(包含文件本身 - 因此,cstdint#include指令中右键单击,然后选择“打开声明”) - 这将显示包含的文件,如果它们被预处理器宏(#ifdef等)排除,则部分会变灰。您可能会立即看到为什么uint32_t不被视为已定义。在我的例子中,__cplusplus宏有一个不合适的值,这导致我-std=c++11如上所述添加到编译器命令行 -我仍然需要在问题完全解决之前重建索引。

回答by Laurenz

Try to enable the CDT GCC Built-in Compiler Settingsin Project>Properties>Preprocessor Includes>Providers.

尝试在 Project>Properties>Preprocessor Includes>Providers 中启用CDT GCC 内置编译器设置

回答by Sookhee Park

After adding -std=c++11, do this:

添加后-std=c++11,执行以下操作:

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

C/C++ 通用 -> 路径和符号 -> 符号 -> GNU C++

Click Addon the left side and paste __GXX_EXPERIMENTAL_CXX0X__(ensure to append and prepend two underscores) into Nameand leave Valueblank.

单击Add左侧并粘贴__GXX_EXPERIMENTAL_CXX0X__(确保添加并预先添加两个下划线)NameValue留空。