c-rpc远程过程编译错误



我正在linux上开发一个rpc示例程序。当我试图编译我的远程过程时,我得到了这个错误:

msg_proc.c:10:7: error: conflicting types for ‘printmessage_1’
In file included from msg_proc.c:8:0:
msg.h:22:15: note: previous declaration of ‘printmessage_1’ was here

这是我用来编译的命令:

cc msg_proc.c msg_svc.c -o msg_server -lnsl

这些是我的头文件和程序文件:

/*msg.h
 *
 * Please do not edit this file.
 * It was generated using rpcgen.
 */
#ifndef _MSG_H_RPCGEN
#define _MSG_H_RPCGEN
#include <rpc/rpc.h>

#ifdef __cplusplus
extern "C" {
#endif

#define MESSAGEPROG 0x20000001
#define PRINTMESSAGEVERS 1
#if defined(__STDC__) || defined(__cplusplus)
#define PRINTMESSAGE 1
extern  int * printmessage_1(char **, CLIENT *);
extern  int * printmessage_1_svc(char **, struct svc_req *);
extern int messageprog_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
#else /* K&R C */
#define PRINTMESSAGE 1
extern  int * printmessage_1();
extern  int * printmessage_1_svc();
extern int messageprog_1_freeresult ();
#endif /* K&R C */
#ifdef __cplusplus
}
#endif
#endif /* !_MSG_H_RPCGEN */

/*
 * msg_proc.c: implementation of the
 * remote procedure "printmessage"
 */
#include <stdio.h>
#include <rpc/rpc.h>
#include "msg.h"
int * printmessage_1(char **msg, struct svc_req *req) {
    static int result; /* must be static! */
    FILE *f;
    f = fopen("/dev/console", "w");
    if (f == (FILE *) NULL) {
        result = 0;
        return (&result);
    }
    fprintf(f, "%sn", *msg);
    fclose(f);
    result = 1;
    return (&result);
}

我的代码出了什么问题?

printmessage_1函数中的参数类型与printmessage_1_svc的声明匹配,而不是与printmessage_1的声明匹配。–Barmar

最新更新