您的位置:首页 > 产品设计 > UI/UE

error: 'uint8_t' does not name a type

2014-01-05 22:10 976 查看


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

都是诸如这样的错误:

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

加入


[code] #include <stdint.h>

就好了。

参加:


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


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


'uint32_t' does
not name a type






up
vote9down
votefavorite

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

c++
share|improve
this question
asked Jun 17 '12 at 5:23





rmtheis

1,72441328

4
Look for stdint.h or <cstdint> 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
 <stdint.h>
? 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

activeoldestvotes

up
vote14down
voteaccepted
You need to include stdint.h
[code] #include <stdint.h>


share|improve
this answer
answered Jun 17 '12 at 5:37





selbie

15.7k41447

4
The "proper" C++ header would be
cstdint
. – paxdiablo Jun
17 '12 at 5:53
add
comment





up
vote8down
vote
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>
.

share|improve
this answer
answered Jun 17 '12 at 5:35





plasma

45817

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. – plasmaJun
17 '12 at 6:01
add
comment
up
vote2down
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:
[code]  #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.

share|improve
this answer
answered Aug 21 '12 at 0:39





Daniel Lemire

7221511

add
comment
up
vote1down
vote
Add the following in the base.mk file. The following 3rd line is important
-include
 $(TOP)/defs.mk

[code]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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐