Type 'uint32_t' could not be resolved

∥☆過路亽.° 提交于 2020-01-01 05:43:09

问题


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.

In the opendnp objects, intellisense doesnt list

__uint32_t however, DOES resolve.

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

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.

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

#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:

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

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


回答1:


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.

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.




回答2:


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




回答3:


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

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

Click Add on the left side and paste __GXX_EXPERIMENTAL_CXX0X__ (ensure to append and prepend two underscores) into Name and leave Value blank.



来源:https://stackoverflow.com/questions/37466808/type-uint32-t-could-not-be-resolved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!