RPC中未定义对'xdr_numbers'引用是什么错误

hgb9j2n6  于 2022-12-03  发布在  其他
关注(0)|答案(1)|浏览(107)

电源.x

struct numbers
{
  int number;
  int power;
};

program POWER_PROG {
    version POWER_VERS {
            int power(numbers) = 1;
    } = 1;
} = 0x31415926;

client.c

#include <stdlib.h>
#include <stdio.h>
#include <rpc/rpc.h>
#include "power.h"

main(argc, argv)
int argc;
char **argv;
{
CLIENT *cl; /* rpc handle */
char *server;

int *result;

    numbers num;

if (argc != 2) {
    fprintf(stderr, "usage:  %s hostname\n", argv[0]);
    exit(1);
}
server = argv[1];   /* get the name of the server */

result = (int *)malloc(sizeof(int));

/* create the client handle */
if ((cl=clnt_create(server, FACT_PROG, FACT_VERS, "udp")) == NULL) 
{
    /* failed! */
    clnt_pcreateerror(server);
    exit(1);
}


num.number=5;
num.power=3;

/* call the procedure bin_date */
if ((result=fact_1(&num, power, cl))==NULL) {
    /* failed ! */
    clnt_perror(cl, server);
    exit(1);
}
printf("Factorial returned from server is : %d\n", *result);

clnt_destroy(cl);   /* get rid of the handle */
exit(0);
}

server.c

#include <rpc/rpc.h>
 #include "power.h"

 int temp;
 int *power_1_svc(numbers *num, struct svc_req *rqstp)
 {
    temp = 1;
    int i;

    for(i=1;i<=num->power;i++)
        temp = temp * (num->number);

    return &temp;
  }

在上面的代码中,只发生了一个错误:

/tmp/cc604P8X.o: In function `power_prog_1':
power_svc.c:(.text+0x4f): undefined reference to `xdr_numbers'
collect2: error: ld returned 1 exit status

我使用以下命令编译了power.x文件:它生成了所有的文件。但是当我试图编译服务器代码时,它给出了上面的错误。

gcc -o server.out -DPRC_SVC_FG server.c power_svc.c

如何解决此错误?

btxsgosb

btxsgosb1#

您很可能忘记在makefile中添加xdr文件(包含结构定义的文件):

gcc -o server.out -DPRC_SVC_FG server.c power_svc.c power_xdr.c

而不是gcc -o server.out -DPRC_SVC_FG server.c power_svc.c

相关问题