无法解析“uint32_t”类型

时间:2022-01-11 20:53:46

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_t to 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_t however, 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.

类型在 中定义( 解析良好)。我可以打开声明,清楚地看到“using:uint32_t;”

In my searching, I've added -std=c++11 to '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.

在我的搜索中,我在“c / c+ Build—>设置—>工具设置—> GCC c++编译器”下为“所有选项”添加了-std=c+ 11,我还重新构建了项目索引并重新启动了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 **** **项目配置调试增量构建

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

建造完毕(用了133ms)

3 个解决方案

#1


4  

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++11 to 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.

我知道这个问题由来已久,但我觉得值得一提的是,我确实遇到了这个问题,能够解决这个问题的方法就是重新构建索引:右键单击项目,“index”,“Rebuild”。你说你重建了索引,但没有用;重要的是,我在为“CDT GCC内置编译器设置”中指定的编译器添加了-std=c++11之后,可以通过打开项目属性找到“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 cstdint within the #include directive, and choose "open declaration") - this will show you the included file, with sections greyed out if they are precluded via preprocessor macros (#ifdef and the like). You may be able to see immediately why uint32_t is not considered defined. In my case, the __cplusplus macro had an unsuitable value and this led me to adding -std=c++11 to the compiler command line as mentioned above - but I still needed to rebuild the index before the problem was fully resolved.

如果没有帮助,最好的路径调试这个问题可能是打开文件cstdint宣言(包含文件本身,所以,右击文件cstdint # include指令,并选择“开放宣言”)——这将给你包含的文件,与灰色的部分如果他们杜绝通过预处理器宏(# ifdef等)。您可能马上就会明白为什么uint32_t没有被定义。在我的例子中,__cplusplus宏有一个不合适的值,这导致我向上面提到的编译器命令行添加-std=c+ 11——但是在问题完全解决之前,我仍然需要重新构建索引。

#2


2  

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

尝试在Project>属性>Preprocessor包含>提供程序中启用CDT GCC内置的编译器设置。

#3


0  

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

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

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

Click Add and paste GXX_EXPERIMENTAL_CXX0X (ensure to append and prepend two underscores) into Name and leave Value blank.

单击Add并将gxx_experimental al_cxx0x(确保在名称中添加和添加两个下划线)并将值留空。

#1


4  

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++11 to 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.

我知道这个问题由来已久,但我觉得值得一提的是,我确实遇到了这个问题,能够解决这个问题的方法就是重新构建索引:右键单击项目,“index”,“Rebuild”。你说你重建了索引,但没有用;重要的是,我在为“CDT GCC内置编译器设置”中指定的编译器添加了-std=c++11之后,可以通过打开项目属性找到“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 cstdint within the #include directive, and choose "open declaration") - this will show you the included file, with sections greyed out if they are precluded via preprocessor macros (#ifdef and the like). You may be able to see immediately why uint32_t is not considered defined. In my case, the __cplusplus macro had an unsuitable value and this led me to adding -std=c++11 to the compiler command line as mentioned above - but I still needed to rebuild the index before the problem was fully resolved.

如果没有帮助,最好的路径调试这个问题可能是打开文件cstdint宣言(包含文件本身,所以,右击文件cstdint # include指令,并选择“开放宣言”)——这将给你包含的文件,与灰色的部分如果他们杜绝通过预处理器宏(# ifdef等)。您可能马上就会明白为什么uint32_t没有被定义。在我的例子中,__cplusplus宏有一个不合适的值,这导致我向上面提到的编译器命令行添加-std=c+ 11——但是在问题完全解决之前,我仍然需要重新构建索引。

#2


2  

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

尝试在Project>属性>Preprocessor包含>提供程序中启用CDT GCC内置的编译器设置。

#3


0  

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

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

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

Click Add and paste GXX_EXPERIMENTAL_CXX0X (ensure to append and prepend two underscores) into Name and leave Value blank.

单击Add并将gxx_experimental al_cxx0x(确保在名称中添加和添加两个下划线)并将值留空。