C++ 'uint32_t' 没有命名类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11069108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'uint32_t' does not name a type
提问by rmtheis
I'm trying to compile a C++ software package that was written in 2007 and I'm getting this error:
我正在尝试编译 2007 年编写的 C++ 软件包,但出现此错误:
error: ‘uint32_t' does not name a type
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.
这发生在使用 g++ 4.5.2 的 64 位 Ubuntu 中。它使用 g++ 4.1.2 在 64 位 CentOS 上编译得很好。
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
?
是否有#include
我遗漏的或编译器标志?或者,我应该使用typedef
分配uint32_t
给 asize_t
还是 an unsigned int
?
回答by selbie
You need to include stdint.h
你需要包括 stdint.h
#include <stdint.h>
回答by plasma
You need to #include <cstdint>
, but that may not always work.
您需要#include <cstdint>
,但这可能并不总是有效。
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.
现在,我说“可能并不总是有效”。这是因为 cstdint 头文件是 C++11 标准的一部分,并不总是在当前的 C++ 编译器上可用(但通常是)。stdint.h 头文件是 C 等价的,是 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>
.
为了获得最佳便携性,boost/cstdint.hpp
如果您愿意使用 boost ,我建议使用 Boost 的标头。否则,您可能会逃脱 #include'ing <cstdint>
。
回答by patti_jane
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!
我在 Mac OSX 10.6.8 上也遇到了同样的问题,不幸的是,将#include <stdint.h>
或添加<cstdint.h>
到相应的文件并没有解决我的问题。然而,经过更多的搜索,我发现这个解决方案建议添加#include <sys/types.h>
它对我来说效果很好!
回答by Daniel Lemire
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?
其他答案假设您的编译器符合 C++11。如果是这样就好了。但是,如果您使用的是较旧的编译器呢?
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.
当然,它不是便携式的。但它可能适用于您的编译器。
回答by gowriganesh
Add the following in the base.mk file. The following 3rd line is important
-include $(TOP)/defs.mk
在 base.mk 文件中添加以下内容。下面的第三行很重要
-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
避免#error 此文件需要编译器和库支持即将推出的 ISO C++ 标准 C++0x。此支持目前处于实验阶段,必须使用 -std=c++0x 或 -std=gnu++0x 编译器选项启用
回答by user3094631
if it happened when you include opencv header.
如果它发生在您包含 opencv 标头时。
I would recommand that change the order of headers.
我会建议更改标题的顺序。
put the opencv headers just below the standard C++ header.
将 opencv 标头放在标准 C++ 标头下方。
like this:
像这样:
#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
回答by Daniel
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:
我在尝试编译从 Internet 下载的库时遇到了同样的问题。就我而言,#include <cstdint>
代码中已经有 a了。我解决了添加一个:
using std::uint32_t;
回答by Rajnish Sharma
just navigate to /usr/include/x86_64-linux-gnu/bits open stdint-uintn.h and add these lines
只需导航到 /usr/include/x86_64-linux-gnu/bits 打开 stdint-uintn.h 并添加这些行
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
再次打开 stdint-intn.h 并添加
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..
请注意,这些行已经存在,只需复制并添加缺失的行,加油..
回答by SamiraMiss
You need to include iostream
您需要包含 iostream
#include <iostream>
using namespace std;