2013-03-04 50 views
2

到目前爲止,我假設u_int16_t是一個窗口類型,位於名爲stdint.h的MSVS頭文件中。我正在使用GNU g ++編譯器(實際上是使用mingw的代碼塊),我想知道typedef unsigned short uint_least16_t;(在mingw裏面的stdint.h)是否等價或者我能做些什麼來包含這種類型?gnu中windows stdint.h的u_int16_t的等價物?

這個問題實際上是關於編譯用於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 ===| 
+0

需要更換'u_int16_t:另外,或者如果您使用不同版本的MinGW的(例如,MinGW的4.7+應該使用的<unordered_map>代替<ext/hash_map>)不同的調整可能需要更大的項目的用途'用'uint16_t'和'size_type'用'size_t'。 – antonijn 2013-03-04 07:57:49

回答

0

如果您還沒有任何標題定義u_int16_t。自己動手:

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

typedef uint16_t u_int16_t; 
typedef size_t size_type; 
+1

不要添加這樣的typedefs。糾正使用非標準類型的代碼。 – 2013-03-04 08:49:26

+0

對不起,-1。提問者確實有一個*假設*的頭文件來定義'u_int16_t' - 項目中主要的'sparsetable'頭文件。Michael Burr的回答詳細解釋了它不是配置問題的原因。 – 2013-03-04 09:57:55

+0

@SteveJessop:這就是爲什麼我使用「IF」的理由:-) – deepmax 2013-03-04 10:08:35

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>

+0

看看代碼,我不認爲'size_type'是'size_t'。在至少一個上下文中,它又是'u_int16_t',但是可能有其他上下文,它是'size_t',並且我沒有發現。 – 2013-03-04 09:52:45

0

您應該運行./configure腳本。不幸的是,這可能是Windows上真正的痛苦,因此該項目的./configure將在src/windows目錄中爲VC++生成頭文件。這就是爲什麼u_int16_t適用於VC++ - 它不在任何VC++頭文件中,但config.hsparseconfig.h文件負責處理它。

不幸的是,VC++配置對於MinGW並不適用。理想情況下,你可以運行MinGW的./configure,但正如我所提到的,在Windows上可能很難。這是一個config.h文件,它使我能夠編譯項目的simple_test.cc程序。需要進行相應的更改spareseconfig.h

#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_ */ 
+0

@lost_with_coding:可能值得將此回饋給項目維護者。如果他們爲一個普通的Windows編譯器做了特殊的規定,他們可能願意爲其他人編寫特殊的規定。 – 2013-03-04 09:54:06

+0

是的,我使用MSYS來運行配置,並使之後使用make。除了根據本頁上的答案所做的兩項更改外,代碼中的所有內容都看起來很好,並且運行良好。我不得不在散列時序示例中註釋掉幾行(「easy_hash_map」類有一些問題)。 – pandoragami 2013-03-04 10:33:37

+0

然後我想知道爲什麼configure腳本設置了'HAVE_U_INT16_T'? – 2013-03-04 15:52:31