簡體   English   中英

'uint32_t'沒有命名類型

[英]'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或編譯器標志? 或者,我應該使用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標頭。 否則,你可能能夠逃脫# <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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM