use*_*898 3 compiler-errors visual-c++
我尝试编译使用 node.js 中的 http_parser 的简单 c/c++ 应用程序,我也使用 libuv ,并且基本上尝试在 Windows 中编译此示例。使用 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'
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我试图取消它,但没有奏效。我该怎么做才能通过编译。如果我只是删除它,我会收到此错误:
http_parser.c(180) : error C2061: syntax error : identifier 'unhex'
Run Code Online (Sandbox Code Playgroud)
在此代码部分:
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
};
Run Code Online (Sandbox Code Playgroud)
以及许多其他使用 int8_t 的部分
因为它是 a typedef,所以不能使用#ifdefor#undef等,因为这些只适用于已被#define'ed 的符号。
你能做的最好的事情就是确保两人typedef的意见一致,应该没有问题。
看着stdint-msvc2008.h,可能更容易修改http_parser.h为:
typedef signed __int8 int8_t;
Run Code Online (Sandbox Code Playgroud)
有什么好处?