0

我有以下名为 paper.x 的 .x 文件。当我在 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 */
} = 0x20001234;                      /* 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 文件,我不知道它提到的第 46 行有什么问题

 /*
 * 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 0x20001234
#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 */

所以正确的 .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 */
} = 0x20001234;                      /* Program number */
4

2 回答 2

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 *);

其中之一一定是错的。

于 2012-10-14T23:19:36.580 回答
0

文件paper.h的第46行有什么?. 检查第 46 行的 paper.h 文件,看看函数签名是否相同。它是由 rpcgen 自动生成的吗?

于 2012-10-14T20:07:10.723 回答