'uint32_t'不命名类型

'uint32_t' does not name a type

本文关键字:类型 uint32      更新时间:2023-10-16

我正在尝试编译2007年编写的C++软件包,但出现此错误:

error: ‘uint32_t’ does not name a type

这发生在使用 g++ 4.5.2 的 64 位 Ubuntu 中。它在 64 位 CentOS 上使用 g++ 4.1.2 编译良好。

是否缺少#include或编译器标志?或者,我应该使用 typedefuint32_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标头。否则,您可能能够侥幸逃脱 #include <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

当然,它不是便携式的。但它可能适用于您的编译器。

如果它发生在你包含OpenCV标头时。

我会重新命令更改标题的顺序。

将 OpenCV 标头放在标准 C++ 标头的正下方。

喜欢这个:

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

在 base.mk 文件中添加以下内容。以下第三行很重要 -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 编译器选项启用

我在尝试编译从互联网下载的库时遇到了同样的问题。就我而言,代码中已经有一个#include <cstdint>。我解决了它,并添加了:

using std::uint32_t;

只需导航到/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;

再次打开 stdint-intn.h 并添加

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

请注意,这些行已经存在,只需复制并添加缺少的行干杯。.

你需要包括iostream

#include <iostream>
using namespace std;