2013-12-09 62 views
0

我正在研究Linux上的rpc示例程序。當我嘗試編譯我的遠程過程我得到這個錯誤: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 

這是我用來complie命令:

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, "%s\n", *msg); 
    fclose(f); 
    result = 1; 
    return (&result); 
} 

我的代碼有什麼問題?

+2

「printmessage_1」函數中的參數類型與「printmessage_1_svc」的聲明匹配,而不是「printmessage_1」。 – Barmar

+0

謝謝我的問題解決了。我必須在我的客戶端應用程序中使用printmessage_1_svc而不是printmessage_1。 – hamedkh

回答

0

printmessage_1函數中的參數類型與printmessage_1_svc的聲明匹配,而不是printmessage_1。 - Barmar