2

到目前为止,我假设这u_int16_t是一个名为 stdint.h 的 MSVS 头文件中某处的 Windows 类型。我正在将 GNU g++ 用于编译器(实际上是带有 mingw 的代码块),我想知道typedef unsigned short uint_least16_t;(在 mingw 的 stdint.h 内部)是否是等价的,或者我能做些什么来包含这种类型?

这个问题实际上与编译用于 MSVS 的google sparsehash项目文件有关,但我使用的是代码块。这是它给我的错误(顺便说一句,错误重复了很多次)。

c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|40|error: 'u_int16_t' does not name a type|

继承人的完整日志最多 50 个错误。

||=== simple_test, Debug Win32 ===|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|40|error: 'u_int16_t' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|563|error: 'u_int16_t' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|582|error: 'u_int16_t' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|637|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|638|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|639|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|640|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|641|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|643|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|665|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|698|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|708|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|717|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|742|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|798|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|799|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|802|error: 'size_type' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|807|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|817|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|823|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|831|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|835|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|847|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|857|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|871|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|895|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|910|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|924|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|939|error: 'size_type' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|1093|error: 'u_int16_t' has not been declared|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|1098|error: 'u_int16_t' does not name a type|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable||In member function 'google::table_iterator<google::sparsegroup<T, GROUP_SIZE, Alloc> > google::sparsegroup<T, GROUP_SIZE, Alloc>::end()':|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|597|error: there are no arguments to 'size' that depend on a template parameter, so a declaration of 'size' must be available|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|597|note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable||In member function 'google::const_table_iterator<google::sparsegroup<T, GROUP_SIZE, Alloc> > google::sparsegroup<T, GROUP_SIZE, Alloc>::end() const':|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|598|error: there are no arguments to 'size' that depend on a template parameter, so a declaration of 'size' must be available|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable||In member function 'int google::sparsegroup<T, GROUP_SIZE, Alloc>::bmtest(int) const':|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|639|error: there are no arguments to 'charbit' that depend on a template parameter, so a declaration of 'charbit' must be available|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|639|error: there are no arguments to 'modbit' that depend on a template parameter, so a declaration of 'modbit' must be available|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable||In member function 'void google::sparsegroup<T, GROUP_SIZE, Alloc>::bmset(int)':|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|640|error: there are no arguments to 'charbit' that depend on a template parameter, so a declaration of 'charbit' must be available|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|640|error: there are no arguments to 'modbit' that depend on a template parameter, so a declaration of 'modbit' must be available|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable||In member function 'void google::sparsegroup<T, GROUP_SIZE, Alloc>::bmclear(int)':|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|641|error: there are no arguments to 'charbit' that depend on a template parameter, so a declaration of 'charbit' must be available|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|641|error: there are no arguments to 'modbit' that depend on a template parameter, so a declaration of 'modbit' must be available|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable||In member function 'void google::sparsegroup<T, GROUP_SIZE, Alloc>::set_aux(int, google::true_type)':|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|851|error: 'size_type' was not declared in this scope|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|851|error: expected ';' before 'i'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|851|error: 'i' was not declared in this scope|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable||In member function 'typename Alloc::rebind<T>::other::reference google::sparsegroup<T, GROUP_SIZE, Alloc>::set(int, typename Alloc::rebind<T>::other::const_reference)':|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|872|error: 'size_type' was not declared in this scope|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|872|error: expected ';' before 'offset'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|875|error: 'offset' was not declared in this scope|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|884|error: 'offset' was not declared in this scope|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|890|error: 'offset' was not declared in this scope|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable||In member function 'void google::sparsegroup<T, GROUP_SIZE, Alloc>::erase_aux(int, google::true_type)':|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|917|error: 'size_type' was not declared in this scope|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|917|error: expected ';' before 'i'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\sparsehash\sparsetable|917|error: 'i' was not declared in this scope|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|
4

3 回答 3

0

如果您没有任何定义u_int16_t. 自己做 :

#include <stdint.h>
#include <stddef.h>

typedef uint16_t u_int16_t;
typedef size_t size_type;
于 2013-03-04T07:58:58.057 回答
0

我不确定如何u_int16_t指定;正如您所注意到的,它是非标准的。你应该使用什么取决于你想要什么:

uint16_t        //  Exactly 16 bits, only present if the hardware
                //  has such a type.
uint_least16_t  //  The smallest type which has at least 16 bits.
uint_fast16_t   //  The fastest type which has at least 16 bits.

在大多数现代机器上,这三个通常都是相同类型的 typedef unsigned short,我经常uint16_t 在“可移植”代码中使用,因为它最容易编写,而且我遇到未定义机器的机会是非常非常苗条。(唯一不会定义它的现代机器是 Unisys 大型机和一些嵌入式处理器,具有 32 位字节。)

至于size_type,这大概 size_t就是。在 <stddef.h><cstddef>(在哪里std::size_t),而不是在<stdint.h>

于 2013-03-04T08:47:54.140 回答
0

您应该运行该./configure脚本。不幸的是,这在 Windows 上可能是一个真正的痛苦,因此该项目./configure的目录中包含为 VC++ 生成的标头src/windows。这就是为什么u_int16_t适用于 VC++ - 它不在任何 VC++ 头文件中,但config.handsparseconfig.h文件会处理它。

不幸的是,VC++ 配置不适用于 MinGW。理想情况下,您可以运行./configureMinGW,但正如我提到的,这在 Windows 上可能很困难。这是一个config.h使我能够编译项目simple_test.cc程序的文件。需要对spareseconfig.h. 此外,对于项目的更大用途或者如果您使用不同版本的 MinGW(例如,MinGW 4.7+ 可能应该使用<unordered_map>而不是<ext/hash_map>),可能需要进行不同的调整:

#ifndef GOOGLE_SPARSEHASH_WINDOWS_CONFIG_H_
#define GOOGLE_SPARSEHASH_WINDOWS_CONFIG_H_

/* src/config.h.in.  Generated from configure.ac by autoheader.  */

/* Namespace for Google classes */
#define GOOGLE_NAMESPACE  ::google

/* the location of the header defining hash functions */
#define HASH_FUN_H  <ext/hash_map>

/* the location of <unordered_map> or <hash_map> */
#define HASH_MAP_H  <ext/hash_map>

/* the namespace of the hash<> function */
#define HASH_NAMESPACE  __gnu_cxx

/* the location of <unordered_set> or <hash_set> */
#define HASH_SET_H  <hash_set>

/* Define to 1 if you have the <google/malloc_extension.h> header file. */
#undef HAVE_GOOGLE_MALLOC_EXTENSION_H

/* define if the compiler has hash_map */
#define HAVE_HASH_MAP  1

/* define if the compiler has hash_set */
#define HAVE_HASH_SET  1

/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H

/* Define to 1 if the system has the type `long long'. */
#define HAVE_LONG_LONG  1

/* Define to 1 if you have the `memcpy' function. */
#define HAVE_MEMCPY  1

/* Define to 1 if you have the `memmove' function. */
#define HAVE_MEMMOVE  1

/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

/* define if the compiler implements namespaces */
#define HAVE_NAMESPACES  1

/* Define if you have POSIX threads libraries and header files. */
#undef HAVE_PTHREAD

/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H  1

/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H  1

/* Define to 1 if you have the <sys/resource.h> header file. */
#undef HAVE_SYS_RESOURCE_H

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H  1

/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H  1

/* Define to 1 if you have the <sys/utsname.h> header file. */
#undef HAVE_SYS_UTSNAME_H

/* Define to 1 if the system has the type `uint16_t'. */
#undef HAVE_UINT16_T

/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

/* define if the compiler supports unordered_{map,set} */
#undef HAVE_UNORDERED_MAP

/* Define to 1 if the system has the type `u_int16_t'. */
#undef HAVE_U_INT16_T

/* Define to 1 if the system has the type `__uint16'. */
#define HAVE___UINT16  1

/* Name of package */
#undef PACKAGE

/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT

/* Define to the full name of this package. */
#undef PACKAGE_NAME

/* Define to the full name and version of this package. */
#undef PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME

/* Define to the home page for this package. */
#undef PACKAGE_URL

/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* Define to necessary symbol if this constant uses a non-standard name on
   your system. */
#undef PTHREAD_CREATE_JOINABLE

/* The system-provided hash function including the namespace. */
#define SPARSEHASH_HASH  HASH_NAMESPACE::hash

/* The system-provided hash function, in namespace HASH_NAMESPACE. */
#define SPARSEHASH_HASH_NO_NAMESPACE  hash

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS  1

/* Version number of package */
#undef VERSION

/* Stops putting the code inside the Google namespace */
#define _END_GOOGLE_NAMESPACE_  }

/* Puts following code inside the Google namespace */
#define _START_GOOGLE_NAMESPACE_   namespace google {


// ---------------------------------------------------------------------
// Extra stuff not found in config.h.in

#define HAVE_WINDOWS_H  1   // used in time_hash_map

// This makes sure the definitions in config.h and sparseconfig.h match
// up.  If they don't, the compiler will complain about redefinition.
#include <sparsehash/internal/sparseconfig.h>

// TODO(csilvers): include windows/port.h in every relevant source file instead?
//#include "windows/port.h"

#endif  /* GOOGLE_SPARSEHASH_WINDOWS_CONFIG_H_ */
于 2013-03-04T09:47:57.727 回答