'uint32_t' does not name type

I am trying to compile a C ++ software package that was written in 2007, and I get this error:

error: 'uint32_t' does not name a type

This happens on 64-bit Ubuntu using g ++ 4.5.2. It compiles fine on 64-bit CentOS using g ++ 4.1.2.

Is there a #include or compiler flag that I am missing? Or, should typedef be used to assign uint32_t size_t or perhaps unsigned int ?

+65
c ++ cstdint uint32-t
Jun 17 '12 at 5:23
source share
8 answers

You need to enable stdint.h

  #include <stdint.h> 
+129
Jun 17 2018-12-12T00:
source share

You need #include <cstdint> , but this may not always work.

The problem is that some compilers often automatically export names defined in different headers or provided types before such standards were in place.

Now I said that "may not always work." This is because the cstdint header is part of the C ++ 11 standard and is not always available for current C ++ compilers (but this often happens). The stdint.h header is the equivalent of C and is part of C99.

For better portability, I would recommend using the boost/cstdint.hpp if you want to use boost. Otherwise, you can probably get away with C # include'ing <cstdint> .

+31
Jun 17 '12 at 5:35
source share

I also ran into the same problem on Mac OSX 10.6.8 and unfortunately adding #include <stdint.h> or <cstdint.h> to the appropriate file, I did not solve my problem. However, after a larger search, I found this solution suggesting adding #include <sys/types.h> , which worked fine for me!

+9
Mar 13 '14 at 2:35
source share

Other answers suggest that your compiler is compatible with C ++ 11. This is normal if that is the case. But what if you use an old compiler?

I took the next hack somewhere on the net. It works well enough for me:

  #if defined __UINT32_MAX__ or UINT32_MAX #include <inttypes.h> #else typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned long uint32_t; typedef unsigned long long uint64_t; #endif 

Of course, he is not tolerated. But this may work for your compiler.

+5
Aug 21 2018-12-12T00: 00Z
source share

Add the following to the base.mk file. The next 3rd line is important -include $(TOP)/defs.mk

 CFLAGS=$(DEBUG) -Wall -W -Wwrite-strings CFLAGS_C=-Wmissing-prototypes CFLAGS_CXX=-std=c++0x LDFLAGS= LIBS= 

to avoid #error This file requires compiler and library support for the upcoming ISO C ++ standard, C ++ 0x. This support is currently experimental and should be included with the options -std = C ++ 0x or -std = gnu ++ 0x

+1
Feb 11
source share

if this happened when you include the opencv header.

I would recommend reordering the headers.

put opencv headers just below the standard C ++ header.

like this:

 #include<iostream> #include<opencv2/core/core.hpp> #include<opencv2/highgui/highgui.hpp> 
+1
Sep 18 '15 at 5:35
source share

I had the same problem trying to compile a lib downloaded from the internet. In my case, the code already had #include <cstdint> . I decided that I added:

 using std::uint32_t; 
+1
Apr 05 '16 at 12:15
source share

Add the following to the base.mk file. The next 3rd line is important - turn on $ (TOP) /defs.mk

 CXXFLAGS = -g -std=c++11 -O3 -W -Wall -pedantic -Wpointer-arith -Wwrite-strings -Wno-long-long $(THREADSCXXFLAGS) 
0
May 26 '17 at 13:33
source share



All Articles