【问题标题】:visual studio 2008 error C2371: 'int8_t' : redefinition; different basic types (http_parser.h)Visual Studio 2008 错误 C2371:'int8_t':重新定义;不同的基本类型(http_parser.h)
【发布时间】:2013-05-07 08:57:26
【问题描述】:

我尝试编译使用来自 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 的部分

【问题讨论】:

    标签: visual-c++ compiler-errors


    【解决方案1】:

    因为它是typedef,所以您不能使用#ifdef#undef 等,因为它们仅适用于#define'ed 的符号。

    你能做的最好是确保两个typedef一致,应该没有问题。

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

    typedef signed __int8 int8_t;
    

    有什么好处吗?

    【讨论】:

    • 你能告诉我为什么添加签名解决了这个问题吗?
    • @user63898 - 我猜是因为__int8 可以是有符号或无符号的,并且编译器在比较typedef 时坚持认为修饰符是一样的。尽管 signed 是默认值(根据 MSDN),但编译器选项可以使 unsigned 成为默认值。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多