【问题标题】:compile rpcgen program on ubuntu在 ubuntu 上编译 rpcgen 程序
【发布时间】:2012-12-04 04:33:22
【问题描述】:

我是 rpcgen 编程的新手。 在 ubuntu 上编译以下示例 rpcgen 示例时出现错误。主要功能是计算给定数字的平方

正方形.X

struct square_in {
 long arg1;
 };

struct square_out {
long    res1;
};

program SQUARE_PROG {
version SQUARE_VERS {
square_out  SQUAREPROC(square_in) = 1;
                    /* procedure number = 1 */
} = 1;              /* version number = 1 */
} = 0x31230000;         /* program number = 0x31230000 */

client.c

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

int
main(int argc, char **argv)
  {
CLIENT      *cl;
square_in   in;
square_out  *outp;

if (argc != 3)
    //err_quit("usage: client <hostname> <integer-value>");
    exit(0);

cl = clnt_create(argv[1], SQUARE_PROG, SQUARE_VERS, "tcp");

in.arg1 = atol(argv[2]);
if ( (outp = squareproc_1(&in, cl)) == NULL)
    //err_quit("%s", clnt_sperror(cl, argv[1]));
   exit(0);

printf("result: %ld\n", outp->res1);
exit(0);
 }

服务器.c

#include    <rpc/rpc.h>
#include    "square.h"
#include <stdio.h>


     square_out *
    squareproc_1_svc(square_in *inp, struct svc_req *rqstp)
     {
static square_out   out;

printf("thread %d started, arg = %ld\n",
       pr_thread_id(NULL), inp->arg1);
sleep(5);
out.res1 = inp->arg1 * inp->arg1;
printf("thread %d done\n", pr_thread_id(NULL));

return(&out);
       }

制作文件:

PROGS = client server
CFLAGS += -DDEBUG

all:    ${PROGS}

square.h square_clnt.c square_svc.c square_xdr.c:   square.x
            rpcgen -C square.x

square_clnt.o: square_clnt.c square.h

square_svc.o: square_svc.c square.h

client: square.h client.o square_clnt.o square_xdr.o
            ${CC} ${CFLAGS} -o $@ client.o square_clnt.o square_xdr.o \
                ${LIBS} ${LIBS_RPC}

server: square.h server.o square_svc.o square_xdr.o
            ${CC} ${CFLAGS} -o $@ server.o square_svc.o square_xdr.o \
                ${LIBS} ${LIBS_RPC}

clean:
        rm -f ${PROGS} ${CLEANFILES} *_clnt.c *_svc.c *_xdr.c square.h

在执行时,我收到以下错误:

cc -DDEBUG   -c -o client.o client.c
cc -DDEBUG -o client client.o square_clnt.o square_xdr.o \

cc -DDEBUG   -c -o server.o server.c
cc -DDEBUG -o server server.o square_svc.o square_xdr.o \

server.o: In function `squareproc_1_svc':
server.c:(.text+0x14): undefined reference to `pr_thread_id'
server.c:(.text+0x52): undefined reference to `pr_thread_id'
collect2: error: ld returned 1 exit status
make: *** [server] Error 1

【问题讨论】:

    标签: rpc ubuntu-12.04


    【解决方案1】:

    像这样使用服务器文件

    // SERVER FILE: server.c
    
    #include"rpc/rpc.h"
    #include"square.h"
    #include"stdio.h"
    #include"stdlib.h"
    #include"math.h"
    
    square_out *squareproc_1_svc(square_in *inp,struct svc_req *rqstp)
    {
    
        static square_out out;
        out.res1 = inp->arg1 * inp->arg1;
        return(&out);
    }
    

    并使用

    运行程序
    [root@localhost ~]# rpcgen -C square.x
    [root@localhost ~]# cc -c client.c -o client.o
    [root@localhost ~]# cc -c square_clnt.c -o square_clnt.o
    [root@localhost ~]# cc -c square_xdr.c -o square_xdr.o
    [root@localhost ~]# cc -o client client.o square_clnt.o square_xdr.o
    [root@localhost ~]# cc -c client.c server.c square_xdr.c
    [root@localhost ~]# cc -c server.c -o server.o
    [root@localhost ~]# cc -c square_svc.c -o square_svc.o
    [root@localhost ~]# cc -o server server.o square_svc.o square_xdr.o
    [root@localhost ~]# ./server &
    
    [1] 3334
    
    [root@localhost ~]# ./client localhost 4
    
    result is : 16
    

    【讨论】:

      【解决方案2】:

      我认为您不需要使用pr_thread_id。尝试不使用它进行编译。

      【讨论】:

        猜你喜欢
        • 2015-08-11
        • 2012-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-23
        • 1970-01-01
        相关资源
        最近更新 更多