我有以下名为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 */
答案 0 :(得分: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 *);
其中一个肯定是错的。
答案 1 :(得分:0)
文件paper.h的第46行有什么作用? 。检查第46行的paper.h文件,看看函数签名是否相同。是否由rpcgen自动生成?