3

i try to compile simple c/c++ app that is using http_parser from node.js i also using libuv , and basically trying to compile this example in windows. using visual studio 2008

but i getting this compilation error :

>d:\dev\cpp\servers\libuv\libuv_http_server\http_parser.h(35) : error C2371: 'int8_t' : redefinition; different basic types
1>        d:\dev\cpp\servers\libuv\libuv-master\libuv-master\include\uv-private\stdint-msvc2008.h(82) : see declaration of 'int8_t'

the code in the http_parser.h file looks like this:

#include <sys/types.h>
#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
#include <BaseTsd.h>
#include <stddef.h>
//#undef __int8
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif

as you can see i tryed to undef it but it didnt worked. what can i do so it will pass compilation . if i just remove it im getting this error :

http_parser.c(180) : error C2061: syntax error : identifier 'unhex'

on this code section :

static const int8_t unhex[256] =
  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  , 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1
  ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
  };

and many other sections that using int8_t

leppie
  • 115,091
  • 17
  • 196
  • 297
user63898
  • 29,839
  • 85
  • 272
  • 514

2 Answers2

5

As it's a typedef, you can't use #ifdef or #undef etc, because these only work with symbols that have been #define'ed.

The best you can do is to make sure that the two typedef's agree, the there should be no problem.

Looking at stdint-msvc2008.h, it might be easier to modify http_parser.h to this:

typedef signed __int8 int8_t;

Any good?

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
  • can you please tell me why adding signd to it solved the problem ? – user63898 May 07 '13 at 12:45
  • 1
    @user63898 - I guess because `__int8` can be signed or unsigned and the compiler is being pedantic when comparing the `typedef`'s to insist that the modifiers are the same. Although `signed` is default (according to MSDN) a compiler option can make `unsigned` the default. – Roger Rowland May 07 '13 at 12:56
1

Try #define HAVE_STDINT_H 1 at the top of your code to avoid redefinition of int8_t.

afs_mp
  • 77
  • 1
  • 9