2012-10-14 84 views
0

我有以下.x文件,名爲paper.x。當我以撥打以下錯誤時,函數創建RPC服務器RPC - 衝突類型錯誤

paperserverproc.c:23:5:錯誤:衝突的類型「add_procedure_1_svc」 paper.h:46:15:注意:先前的「add_procedure_1_svc」宣言在這裏

#include <limits.h> 
struct paper_saved{ 
    char author_name[CHAR_MAX]; 
    char paper_title[CHAR_MAX]; 
    int paper_id; 
    char paper_file_name[CHAR_MAX]; 
    char paper_content[CHAR_MAX]; 
}; 
struct paper_info_saved{ 
    char author_name[CHAR_MAX]; 
    char paper_title[CHAR_MAX]; 
    int paper_id; 
    char paper_file_name[CHAR_MAX]; 

}; 
struct list_papers{ 
    paper_saved paper; 
    struct list_papers *next; 
}; 

program PAPER_PROGRAM 
{ 
    version PAPER_VERSION 
    { 
    int ADD_PROCEDURE(paper_saved) = 1;  /* Procedure nb */ 
    void LIST_PROCEDURE(void)=2; 
    paper_info_saved INFO_PROCEDURE(int)=3; 
    paper_saved FETCH_PROCEDURE(int)=4; 
    void REMOVE_PROCEDURE(int)=5; 
    } = 1;        /* Version nb */ 
} = 0x200;      /* Program number */ 

我打電話的方法,用這種方式和行23行,當我宣佈函數如下

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <unistd.h> 
#include "paper.h" 
#include <ctype.h> 
#include <limits.h> 
....... 
int add_procedure_1_svc(paper_saved *paper_pointer, struct svc_req *rqstp) 

這是通過的rpcgen產生的文件paper.h,我不知道那是什麼它提到

/* 
* Please do not edit this file. 
* It was generated using rpcgen. 
*/ 

#ifndef _PAPER_H_RPCGEN 
#define _PAPER_H_RPCGEN 

#include <rpc/rpc.h> 


#ifdef __cplusplus 
extern "C" { 
#endif 


struct paper_saved { 
    char author_name[127]; 
    char paper_title[127]; 
    int paper_id; 
    char paper_file_name[127]; 
    char paper_content[127]; 
}; 
typedef struct paper_saved paper_saved; 

struct paper_info_saved { 
    char author_name[127]; 
    char paper_title[127]; 
    int paper_id; 
    char paper_file_name[127]; 
}; 
typedef struct paper_info_saved paper_info_saved; 

struct list_papers { 
    paper_saved paper; 
    struct list_papers *next; 
}; 
typedef struct list_papers list_papers; 

#define PAPER_PROGRAM 0x200
#define PAPER_VERSION 1 

#if defined(__STDC__) || defined(__cplusplus) 
#define ADD_PROCEDURE 1 
extern int * add_procedure_1(paper_saved *, CLIENT *); 
extern int * add_procedure_1_svc(paper_saved *, struct svc_req *); 
#define LIST_PROCEDURE 2 
extern void * list_procedure_1(void *, CLIENT *); 
extern void * list_procedure_1_svc(void *, struct svc_req *); 
#define INFO_PROCEDURE 3 
extern paper_info_saved * info_procedure_1(int *, CLIENT *); 
extern paper_info_saved * info_procedure_1_svc(int *, struct svc_req *); 
#define FETCH_PROCEDURE 4 
extern paper_saved * fetch_procedure_1(int *, CLIENT *); 
extern paper_saved * fetch_procedure_1_svc(int *, struct svc_req *); 
#define REMOVE_PROCEDURE 5 
extern void * remove_procedure_1(int *, CLIENT *); 
extern void * remove_procedure_1_svc(int *, struct svc_req *); 
extern int paper_program_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t); 

#else /* K&R C */ 
#define ADD_PROCEDURE 1 
extern int * add_procedure_1(); 
extern int * add_procedure_1_svc(); 
#define LIST_PROCEDURE 2 
extern void * list_procedure_1(); 
extern void * list_procedure_1_svc(); 
#define INFO_PROCEDURE 3 
extern paper_info_saved * info_procedure_1(); 
extern paper_info_saved * info_procedure_1_svc(); 
#define FETCH_PROCEDURE 4 
extern paper_saved * fetch_procedure_1(); 
extern paper_saved * fetch_procedure_1_svc(); 
#define REMOVE_PROCEDURE 5 
extern void * remove_procedure_1(); 
extern void * remove_procedure_1_svc(); 
extern int paper_program_1_freeresult(); 
#endif /* K&R C */ 

/* the xdr functions */ 

#if defined(__STDC__) || defined(__cplusplus) 
extern bool_t xdr_paper_saved (XDR *, paper_saved*); 
extern bool_t xdr_paper_info_saved (XDR *, paper_info_saved*); 
extern bool_t xdr_list_papers (XDR *, list_papers*); 

#else /* K&R C */ 
extern bool_t xdr_paper_saved(); 
extern bool_t xdr_paper_info_saved(); 
extern bool_t xdr_list_papers(); 

#endif /* K&R C */ 

#ifdef __cplusplus 
} 
#endif 

#endif /* !_PAPER_H_RPCGEN */ 

在第46行的問題,所以正確的.h文件中是

#include <limits.h> 
struct paper_saved{ 
    char author_name[CHAR_MAX]; 
    char paper_title[CHAR_MAX]; 
    int paper_id; 
    char paper_file_name[CHAR_MAX]; 
    char paper_content[CHAR_MAX]; 
}; 
struct paper_info_saved{ 
    char author_name[CHAR_MAX]; 
    char paper_title[CHAR_MAX]; 
    int paper_id; 
    char paper_file_name[CHAR_MAX]; 

}; 
struct list_papers{ 
    paper_saved paper; 
    struct list_papers *next; 
}; 
typedef int p_id; 
program PAPER_PROGRAM 
{ 
    version PAPER_VERSION 
    { 
    p_id ADD_PROCEDURE(paper_saved) = 1;  /* Procedure nb */ 
    void LIST_PROCEDURE(void)=2; 
    paper_info_saved INFO_PROCEDURE(int)=3; 
    paper_saved FETCH_PROCEDURE(int)=4; 
    void REMOVE_PROCEDURE(int)=5; 
    } = 1;        /* Version nb */ 
} = 0x200;      /* Program number */ 

回答

1

該函數聲明爲返回int

int add_procedure_1_svc(paper_saved *paper_pointer, struct svc_req *rqstp) 

extern爲返回int*

extern int * add_procedure_1_svc(paper_saved *, struct svc_req *); 

其中之一肯定是錯誤的。

+0

男人就是這個問題!你是對的!我應該在.h文件的typedef int p_id中添加一個lin,並將p_id設置爲該過程的返回值。謝謝! @BinyaminSharet –

0

什麼文件紙行46 .h有? 。檢查第46行的paper.h文件以查看函數簽名是否相同。是否由rpcgen自動生成?

+0

我已經添加了由rpcgen生成的paper.h文件。如果你能找到問題的人,我會很高興。 @RanjithRuban –