2

So far I'm assuming that u_int16_t is a windows type somewhere inside of an MSVS header file called stdint.h. I'm using GNU g++ for a compiler (actually codeblocks with mingw) and I wondered if typedef unsigned short uint_least16_t; (inside stdint.h for mingw) is the equivalent or what could I do to include this type?

This question is actually in relation to compiling the google sparsehash project files meant for MSVS but I'm using codeblocks. This was the error it gave me (btw, the error repeated many times over).

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|

Heres the full log up to 50 errors.

||=== 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 ===|
pandoragami
  • 5,387
  • 15
  • 68
  • 116

3 Answers3

1

If you haven't any header which defines u_int16_t. Do it yourself :

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

typedef uint16_t u_int16_t;
typedef size_t size_type;
masoud
  • 55,379
  • 16
  • 141
  • 208
  • 3
    Don't add such typedefs. Correct the code which uses the non-standard type. – James Kanze Mar 04 '13 at 08:49
  • Sorry, -1. The questioner does have a header that's *supposed* to define `u_int16_t` -- the main `sparsetable` header in the project. The reason it doesn't is a configure problem as Michael Burr's answer explains in detail. – Steve Jessop Mar 04 '13 at 09:57
  • @SteveJessop: It's the reason of why I used "IF" :-) – masoud Mar 04 '13 at 10:08
  • @Steve nope. I ran ./configure using MSYS and that still missed it. I simply don't have that file on my machine anywhere. I do have stdint.h but not with the correct type. – pandoragami Mar 04 '13 at 10:36
  • @lost_with_coding: I don't understand which file it is that is missing from your machine. I don't have the source open in front of me any more, but it has several fallback options including to `unsigned short`, and configure *should* have set the defines to select one of them. Basically the line M M. proposes, `typedef uint16_t u_int16_t;` is already in the source, so if it's correct then the trick is not to add it yourself, it's to persuade the preprocessor to emit it :-) Maybe the configure script itself is broken (for your platform, Windows/mingw). – Steve Jessop Mar 04 '13 at 10:42
  • @Steve I'll be honest with you I don't know much about this stuff especially when it comes to compiling anything using `make` on windows. Mingw is crap and that I do know but whats the alternative for gnu on windows? cygwin...I don't wanna be tied to a cygwin.dll everywhere I go. – pandoragami Mar 04 '13 at 10:53
0

I'm not sure how u_int16_t is specified; as you have noticed, it's non standard. What you should use depends on what you want:

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.

On most modern machines, all three will be a typedef to the same type, normally unsigned short, and I regularly use uint16_t in "portable" code, since it's the easiest to write, and the chance of my encountering a machine where it isn't defined is very, very slim. (The only modern machines where it won't be defined are the Unisys mainframes and some embedded processors, with 32 bit bytes.)

With regards to size_type, this is probably size_t. In <stddef.h> or <cstddef> (where it is std::size_t), rather than in <stdint.h>.

James Kanze
  • 150,581
  • 18
  • 184
  • 329
  • Looking at the code, I don't think `size_type` is `size_t`. In at least one context it's `u_int16_t` again, but there may be other contexts in which it's `size_t` and that I didn't spot. – Steve Jessop Mar 04 '13 at 09:52
0

You should run the ./configure script. Unfortunately that can be a real pain on Windows, so the project has the headers that ./configure would produce for VC++ in the src/windows directory. That's why u_int16_t works for VC++ - it's not in any of the VC++ headers, but the config.h and sparseconfig.h files take care of it.

Unfortunately, the VC++ configuration doesn't work well for MinGW. Ideally you'd be able to run ./configure for MinGW, but as I mentioned that can be difficult on Windows. Here's a config.h file that enabled me to compile the project's simple_test.cc program. Corresponding changes need to be made to spareseconfig.h. Also, different tweaks may be necessary for larger uses of the project or if you use a different version of MinGW (for example, MinGW 4.7+ should probably use <unordered_map> instead of <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_ */
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • @lost_with_coding: Probably worth feeding this back to the project's maintainers. If they've made special provision for one common Windows compiler, they might be willing to make special provision for others. – Steve Jessop Mar 04 '13 at 09:54
  • Yes I used MSYS to run configure and also to make the project using make afterwards. Besides the two changes I had to make according to the answer on this page everything looks fine in the code and it runs fine. I did have to comment out a few lines in the hash timing example (the "easy_hash_map" class had some issues). – pandoragami Mar 04 '13 at 10:33