rmtheis
rmtheis

Reputation: 5836

'uint32_t' does not name a type

I'm trying to compile a C++ software package that was written in 2007 and I'm getting this error:

error: ‘uint32_t’ does not name a type

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

Is there an #include or a compiler flag that I'm missing? Or, should I use typedef to assign uint32_t to a size_t or maybe an unsigned int?

Upvotes: 118

Views: 271460

Answers (11)

selbie
selbie

Reputation: 104569

You need to include stdint.h

 #include <stdint.h>

Upvotes: 201

GigaWatts
GigaWatts

Reputation: 123

You should include cstdint, C++11 ratified this practice.

#include <cstdint>

You would need to use the std:: name space. Reference this post: <cstdint> vs. <stdint.h>

Upvotes: 1

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53215

The best practice for C++ code is to include this file:

#include <cstdint>

And use the integer types like this:

std::uint32_t

uint32_t is not guaranteed by the C++ standard to be available in #include <cstdint>, but std::uint32_t is.

This is the same for std::size_t, std::int32_t, std::uint16_t, etc.

Upvotes: 1

SamiraMiss
SamiraMiss

Reputation: 1

You need to include iostream

#include <iostream>
using namespace std;

Upvotes: -8

Rajnish Sharma
Rajnish Sharma

Reputation: 1

just navigate to /usr/include/x86_64-linux-gnu/bits open stdint-uintn.h and add these lines

typedef __uint8_t uint8_t;
typedef __uint16_t uint16_t;
typedef __uint32_t uint32_t;
typedef __uint64_t uint64_t;

again open stdint-intn.h and add

typedef __int8_t int8_t;
typedef __int16_t int16_t;
typedef __int32_t int32_t;
typedef __int64_t int64_t;

note these lines are already present just copy and add the missing lines cheerss..

Upvotes: -3

plasma
plasma

Reputation: 898

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

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

Now, I said "may not always work." That's because the cstdint header is part of the C++11 standard and is not always available on current C++ compilers (but often is). The stdint.h header is the C equivalent and is part of C99.

For best portability, I'd recommend using Boost's boost/cstdint.hpp header, if you're willing to use boost. Otherwise, you'll probably be able to get away with #include'ing <cstdint>.

Upvotes: 45

Daniel
Daniel

Reputation: 344

I had tha same problem trying to compile a lib I download from the internet. In my case, there was already a #include <cstdint> in the code. I solved it adding a:

using std::uint32_t;

Upvotes: 0

user3094631
user3094631

Reputation: 451

if it happened when you include opencv header.

I would recommand that change the order of headers.

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

like this:

#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>

Upvotes: 1

patti_jane
patti_jane

Reputation: 3871

I also encountered the same problem on Mac OSX 10.6.8 and unfortunately adding #include <stdint.h> or <cstdint.h> to the corresponding file did not solve my problem. However, after more search, I found this solution advicing to add #include <sys/types.h> which worked well for me!

Upvotes: 12

gowriganesh
gowriganesh

Reputation: 27

Add the following in the base.mk file. The following 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 the #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options

Upvotes: 1

Daniel Lemire
Daniel Lemire

Reputation: 3618

The other answers assume that your compiler is C++11 compliant. That is fine if it is. But what if you are using an older compiler?

I picked up the following 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

It is not portable, of course. But it might work for your compiler.

Upvotes: 9

Related Questions