编译错误:named type definition in parentheses解决方案

今天用VC6编译7Z的SDK,报错一大堆:

Compiling...
7zFile.c
F:\VC98\INCLUDE\rpcasync.h(45) : error C2220: warning treated as error - no object file generated
F:\VC98\INCLUDE\rpcasync.h(45) : warning C4115: '_RPC_ASYNC_STATE' : named type definition in parentheses
7zStream.c
Alloc.c
F:\VC98\INCLUDE\rpcasync.h(45) : error C2220: warning treated as error - no object file generated
F:\VC98\INCLUDE\rpcasync.h(45) : warning C4115: '_RPC_ASYNC_STATE' : named type definition in parentheses
LzFind.c
LzFindMt.c
F:\VC98\INCLUDE\rpcasync.h(45) : error C2220: warning treated as error - no object file generated
F:\VC98\INCLUDE\rpcasync.h(45) : warning C4115: '_RPC_ASYNC_STATE' : named type definition in parentheses
LzmaDec.c
LzmaEnc.c
F:\VC98\INCLUDE\rpcasync.h(45) : error C2220: warning treated as error - no object file generated
F:\VC98\INCLUDE\rpcasync.h(45) : warning C4115: '_RPC_ASYNC_STATE' : named type definition in parentheses
LzmaUtil.c
F:\VC98\INCLUDE\rpcasync.h(45) : error C2220: warning treated as error - no object file generated
F:\VC98\INCLUDE\rpcasync.h(45) : warning C4115: '_RPC_ASYNC_STATE' : named type definition in parentheses
Threads.c
F:\VC98\INCLUDE\rpcasync.h(45) : error C2220: warning treated as error - no object file generated
F:\VC98\INCLUDE\rpcasync.h(45) : warning C4115: '_RPC_ASYNC_STATE' : named type definition in parentheses
Generating Code...
Error executing cl.exe.

原因是_RPC_ASYNC_STATE结构体的定义在引用了它的后面,定位到_RPC_ASYNC_STATE定义部分VC98\Include\RPCASYNC.H,查看定义源码如下:

typedef
enum _RPC_ASYNC_EVENT {
    RpcCallComplete,
    RpcSendComplete,
    RpcReceiveComplete
    } RPC_ASYNC_EVENT;

typedef void RPC_ENTRY
RPCNOTIFICATION_ROUTINE (
                  struct _RPC_ASYNC_STATE *pAsync,<span style="white-space:pre">	</span>//这里使用了这个结构体,但是其定义在后面
                  void *Context,                              
                  RPC_ASYNC_EVENT Event);
typedef RPCNOTIFICATION_ROUTINE *PFN_RPCNOTIFICATION_ROUTINE;
    
typedef struct _RPC_ASYNC_STATE {
    unsigned int    Size; // size of this structure
    unsigned long   Signature;
    long   Lock;
    unsigned long   Flags;
    void           *StubInfo;
    void           *UserInfo;
    void           *RuntimeInfo;
    RPC_ASYNC_EVENT Event;

    RPC_NOTIFICATION_TYPES NotificationType;
    union {
        //
        // Notification by APC
        //
        struct {
            PFN_RPCNOTIFICATION_ROUTINE NotificationRoutine;
            HANDLE hThread;
            } APC;

        //
        // Notification by IO completion port
        //
        struct {
            HANDLE hIOPort;
            DWORD dwNumberOfBytesTransferred;
            DWORD dwCompletionKey;
            LPOVERLAPPED lpOverlapped;
            } IOC;

        //
        // Notification by window message
        //
        struct {
            HWND hWnd;
            UINT Msg;
            } HWND;


        //
        // Notification by event
        //
        HANDLE hEvent;

        //
        // Notification by callback function
        //
        // This option is available only to OLE
        //
        PFN_RPCNOTIFICATION_ROUTINE NotificationRoutine;
        } u;

    long Reserved[4]; 
    } RPC_ASYNC_STATE, *PRPC_ASYNC_STATE;



解决方案:

加上前置声明:struct _RPC_ASYNC_STATE。


你可能感兴趣的:(编译错误:named type definition in parentheses解决方案)