error: 'uint8_t' does not name a type

c++里用了c的代码,确切的说,是引用了c写的x264.h,结果报错了:

都是诸如这样的错误:


/x264.h:341:5: error: 'uint8_t' does not name a type


加入


 #include 
就好了。



参加:

http://stackoverflow.com/questions/11069108/uint32-t-does-not-name-a-type

感谢下面讨论的还挺复杂的。



'uint32_t' does not name a type

up vote 9 down vote favorite
3

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 assignuint32_t to a size_t or maybe an unsigned int?

share | improve this question
 
4  
Look for stdint.h or headers. That type is (as I understand it) part of C99 but didn't make it into C++. –   Mike C  Jun 17 '12 at 5:28
2  
Did you #include ? Looks like a possible bug on 64 bit Ubuntu. Also, do you have a -std=c++98 or some such command line option for gcc? If so, can you check if it compiles fine if you use -std=gnu++98? –   dirkgently  Jun 17 '12 at 5:29 
 
@dirkgently I checked the Makefile and there were no std options. –   rmtheis  Jun 17 '12 at 5:59 
 
@user667810: So that defaults to GNU extensions and C++98 mode. –   dirkgently  Jun 17 '12 at 6:00
add comment

4 Answers

active oldest votes
up vote 14 down vote accepted

You need to include stdint.h

 #include 
share | improve this answer
 
4  
The "proper" C++ header would be cstdint. –   paxdiablo  Jun 17 '12 at 5:53
add comment
up vote 8 down vote

You need to #include , 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 .

share | improve this answer
 
 
This gave me #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. –   rmtheis  Jun 17 '12 at 5:58
 
Right, as it says, cstdint is part of the new C++ standard (which was called C++0x but is not, officially, C++11. So to use that header, you have to enable the new standard in g++. Like I said, the best portable way to get these types is to use Boost or some other equivalent header, rather than relying on compiler support. –   plasma Jun 17 '12 at 6:01
add comment
up vote 2 down vote

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

share | improve this answer
  add comment
up vote 1 down vote

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

share | improve this answer

你可能感兴趣的:(c/c++,多媒体/流媒体/live555)