visual studio 2008错误C2371:'int8_t':重新定义;不同的基本类型(http_parser.h)

时间:2013-05-07 08:57:27

标签: visual-c++ compiler-errors

我尝试编译使用node.js中的http_parser的简单c / c ++应用程序 我也使用libuv,基本上尝试在Windows中编译this示例。 使用visual studio 2008

但是我得到了这个编译错误:

>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'

http_parser.h文件中的代码如下所示:

#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

你可以看到我试图取消它但它没有用。 我能做什么呢?它会通过编译。 如果我只是删除它我得到这个错误:

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

在此代码部分:

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
  };

以及使用int8_t

的许多其他部分

2 个答案:

答案 0 :(得分:4)

因为它是typedef,您无法使用#ifdef#undef等,因为这些仅适用于已#define'的符号。

你能做的最好的事情是确保两个typedef同意,应该没有问题。

查看stdint-msvc2008.h,可能更容易将http_parser.h修改为:

typedef signed __int8 int8_t;

有什么好处吗?

答案 1 :(得分:1)

请尝试在代码顶部使用#define HAVE_STDINT_H 1,以避免重新定义int8_t。

相关问题