8

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)

ErikJL
  • 111
  • 1
  • 2
  • 7
  • "I am using the gcc compiler on Debian 8." What gcc version is that? You can check with `gcc -v`. – Chris Beck May 26 '16 at 16:53
  • 1
    Is this causing a compilation error or just the Eclipse UI is marking an error? – James Adkison May 26 '16 at 16:55
  • 1
    Try `std::uint32_t`. There are probably more than one `xxx::uint32_t` in that barrage of `using namespace yyy;`, which makes the name ambiguous. – Baum mit Augen May 26 '16 at 16:55
  • gcc version 4.9.2 (Debian 4.9.2-10) – ErikJL May 26 '16 at 16:58
  • when i try std::uint32_t is still unresolved. The intellisense doesn't show any 'uint' types. – ErikJL May 26 '16 at 17:00
  • It causes a compilation error, not just Eclipse UI error. – ErikJL May 26 '16 at 17:01
  • 1
    Try to move #include //uint32_t to the first line. How opendnp3 refers to uint32_t ? – Vadim Key May 26 '16 at 17:30
  • 2
    Time to cut down the problem. if `#include #include int main() { uint32_t test =0; std::cout << test << std::endl; }` doesn't reproduce the problem, then @BaummitAugen is probably right. – user4581301 May 26 '16 at 17:31
  • I actually just tried to create a new Project without all of the other references, and I still see the same error. – ErikJL May 26 '16 at 17:36
  • Also please specify exact compiler error, does it complain on the first line in your main() ? To check that c++ eleven is enabled just add something like: auto x = "123"; it's c++11 feature – Vadim Key May 26 '16 at 17:36
  • @ErikJL even this doesn't compiles? #include int main() { uint32_t x = 0; cout << x << endl; return 0; } – Vadim Key May 26 '16 at 17:37
  • Yeah, even a fresh HelloWorld project that i only modified by declaring a uint32_t wont' compile. Also, the 'auto x = "123"; ' works just fine. – ErikJL May 26 '16 at 17:41
  • Weird. is `__uint32_t_defined` defined? At this point I don't expect it will be. – user4581301 May 26 '16 at 17:44
  • #include #include using namespace std; int main() { uint32_t i = 0; auto x = "123"; cout << "Foo!" << endl; // prints Foo! return 0; } – ErikJL May 26 '16 at 17:45
  • @user4581301 - __uint32_t DOES resolve. – ErikJL May 26 '16 at 17:46
  • Recommend editing question to include the test code from two comments up. It's more direct and MCVE-y than the code sample you have now. – user4581301 May 26 '16 at 17:52
  • Let's see if this is an Eclipse config problem. If you build the Foo test code from the command line what happens? `g++ -std=c++11 foo.cpp` – user4581301 May 26 '16 at 17:57
  • Good point - just edited it. – ErikJL May 26 '16 at 17:57
  • g++ -std=c++11 foo.cpp creats a binary file 'a.out' but no executable file. – ErikJL May 26 '16 at 18:01
  • a.out should be the executable, but it did compile without warnings or errors, yes? – user4581301 May 26 '16 at 18:16
  • Oh ok yea ./a.out does indeed execute (sorry, I'm very new to both C++ and eclipse). So I have an Eclipse issue then yeah? – ErikJL May 26 '16 at 18:20
  • Why do you always include `using namespace std;`. Is it the case that `std::uint32_t` works? If not, the `using namespace` is noise (and generally a bad idea). If so, that needs to be stressed. Also, edit the `-v` results into the question itself. – Yakk - Adam Nevraumont May 26 '16 at 19:05
  • Wait a second, what evidence do you have that there is a build problem here? ... a squiggle or intellisense only? – Yakk - Adam Nevraumont May 26 '16 at 20:00
  • Recommend copying Eclipse's output in the CDT Build Console (Console tab down at the bottom) and adding it to your question. This will allow us to see both the compiler command line and the error message verbatim. On the dangers of `using namespace std;`, give this a read: http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-in-c-considered-bad-practice – user4581301 May 26 '16 at 20:18
  • @Yakk - std::uint32_t does not resolve in Eclipse, but main.cpp does compile with command line g++. As far as #include std, well, I'm not sure... 95% of my programming is in C# so I'e always used includes instead of fully qualifying types. I did not realize that was bad practice, so thanks for the heads up. Apologize for the ignorance, but what are you referring to when you mention the "-v" results? – ErikJL May 27 '16 at 06:10
  • @erik important information from comment discussions should be put in OP, as comments are deleted often. – Yakk - Adam Nevraumont May 27 '16 at 08:10

3 Answers3

9

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.

davmac
  • 20,150
  • 1
  • 40
  • 68
4

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

Laurenz
  • 1,810
  • 12
  • 25
0

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.

Sadık
  • 4,249
  • 7
  • 53
  • 89