[英]'uint32_t' does not name a type
我正在尝试编译2007年编写的C ++软件包,我收到了这个错误:
error: 'uint32_t' does not name a type
这是在使用g ++ 4.5.2的64位Ubuntu中发生的。 它使用g ++ 4.1.2在64位CentOS上编译良好。
是否存在我缺少的#include
或编译器标志? 或者,我应该使用typedef
将uint32_t
分配给size_t
还是unsigned int
?
你需要包含stdint.h
#include <stdint.h>
你需要#include <cstdint>
,但这可能并不总是有效。
问题是某些编译器通常会在这些标准到位之前自动导出在各种标头或提供的类型中定义的名称。
现在,我说“可能并不总是有效”。 那是因为cstdint标头是C ++ 11标准的一部分,并不总是在当前的C ++编译器上可用(但通常是)。 stdint.h头是C等价物,是C99的一部分。
为了获得最佳的可移植性,如果您愿意使用boost,我建议使用Boost的boost/cstdint.hpp
标头。 否则,你可能能够逃脱# <cstdint>
。
我在Mac OSX 10.6.8上也遇到了同样的问题,遗憾的是将#include <stdint.h>
或<cstdint.h>
到相应的文件并没有解决我的问题。 但是,经过更多的搜索,我发现这个解决方案建议添加#include <sys/types.h>
,这对我来说效果很好!
其他答案假设您的编译器符合C ++ 11。 如果是的话,这很好。 但是,如果您使用较旧的编译器呢?
我在网上的某个地方拿起了下面的黑客。 它对我来说效果很好:
#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
当然,它不便携。 但它可能适用于您的编译器。
在base.mk文件中添加以下内容。 以下第3行很重要 - -include $(TOP)/defs.mk
CFLAGS=$(DEBUG) -Wall -W -Wwrite-strings
CFLAGS_C=-Wmissing-prototypes
CFLAGS_CXX=-std=c++0x
LDFLAGS=
LIBS=
避免#error此文件需要编译器和库支持即将推出的ISO C ++标准C ++ 0x。 此支持目前是实验性的,必须使用-std = c ++ 0x或-std = gnu ++ 0x编译器选项启用
如果它包含opencv标题时发生。
我建议改变标题的顺序。
将opencv头文件放在标准C ++头文件下面。
像这样:
#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
我有同样的问题试图编译我从互联网上下载的lib。 在我的例子中,代码中已经有一个#include <cstdint>
。 我解决了它添加一个:
using std::uint32_t;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.