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

./configureスクリプトを実行する必要があります。残念ながら、これは Windows では大きな問題になる可能性があるため、プロジェクトのディレクトリ./configureには VC++ 用に生成されるヘッダーが含まれています。src/windowsこれが、VC++ で機能する理由u_int16_tです。どの VC++ ヘッダーにもありませんが、ファイルconfig.hsparseconfig.hファイルが処理します。

残念ながら、VC++ 構成は MinGW ではうまく機能しません。MinGW で実行できる./configureのが理想ですが、前述したように、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 に答える
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.

ほとんどの最新のマシンでは、通常unsigned short、3 つすべてが同じ型の typedef になります。また、「移植可能な」コードで定期的に使用uint16_t します。これは、最も書きやすく、定義されていないマシンに遭遇する可能性があるためです。とても、とてもスリム。(定義されていない最新のマシンは、Unisys メインフレームと、32 ビット バイトの一部の組み込みプロセッサのみです。)

に関してはsize_type、これはおそらく size_t. では なく、<stddef.h>または<cstddef>( がある場所) で。std::size_t<stdint.h>

于 2013-03-04T08:47:54.140 に答える