visual studio 2008 error C2371:'int8_t':redefinition;不同的基本类型(http_parser.h) [英] visual studio 2008 error C2371: 'int8_t' : redefinition; different basic types (http_parser.h)

查看:3237
本文介绍了visual studio 2008 error C2371:'int8_t':redefinition;不同的基本类型(http_parser.h)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编译简单的c / c ++应用程序,它使用http_parser从node.js
i也使用libuv,并基本上试图编译这个例子在windows。
使用visual studio 2008



但我收到此编译错误:

 > d:\dev\cpp\servers\libuv\libuv_http_server\http_parser.h(35):error C2371:'int8_t':redefinition;不同的基本类型
1> d:\dev\cpp\servers\libuv\libuv-master\libuv-master\include\uv-private\stdint-msvc2008.h(82):参见'int8_t'$的声明b $ b

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

你可以看到我试图去undef它,但它did not工作。
我可以做什么,它会通过编译。
如果我只是删除它得到这个错误:

  http_parser.c(180):error C2061:语法错误:标识符'unhex'

在此代码段中:


$ b $ $,$,$,$,$,$,$,$,$, -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,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的部分

解决方案

由于它是一个 typedef ,您不能使用 #ifdef #undef 等,因为这些只适用于 #define '的符号。



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



查看 stdint-msvc2008.h ,可能会更容易修改 http_parser.h to this:

  typedef signed __int8 int8_t; 

有什么好处吗?


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

解决方案

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?

这篇关于visual studio 2008 error C2371:'int8_t':redefinition;不同的基本类型(http_parser.h)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆