1

My problem is the following: I'm trying to implement a C RPC example and I keep running into the following compiler error:

remote_exec.c: In function ‘main’:
remote_exec.c:13:3: warning: implicit declaration of function ‘svc_create’
remote_exec.o: In function `main':
remote_exec.c:(.text+0x31): undefined reference to `svc_create'
collect2: ld returned 1 exit status

My code:

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

int main(int argc, char* argv[])
{       
   extern void execute();

   const char* nettype = "tcp";
   int no_of_handles;

   no_of_handles = svc_create(execute, EXECPROG, EXECVERS, nettype);

   svc_run();
   return 0;
}

I really don't know how to solve this. The man page and all the examples I've studied just say to include rpc/rpc.h, however it doesn't seem to work. I am compiling with

gcc -Wall -c
Tudor
  • 61,523
  • 12
  • 102
  • 142
  • What's your OS, and what OS were the examples you're following intended for? – Mat Oct 02 '11 at 13:46
  • I'm using ubuntu 11.04. The examples were targeting linux. – Tudor Oct 02 '11 at 13:56
  • Strange, I don't think that API exists on Linux (it's Sun RPC I think). Link to that example? – Mat Oct 02 '11 at 14:05
  • If you go here: http://www.cs.cf.ac.uk/Dave/C/node33.html it is listed in the "Top level routines" section. – Tudor Oct 02 '11 at 14:11
  • 1
    That doesn't reference Linux. It's "UNIX" in general, but in that case it uses Sun's RPC library which is not (as far as I know/can find) portable. – Mat Oct 02 '11 at 14:15

2 Answers2

2

There is no such function as svc_create on linux in libc. See the manpage for rpc. Your guide is using the transport independent(ti) RPC library of Solaris and other unixes. See this question for RPC guides for linux.

The RPC library in linux is based on a slightly different RPC library than the ti-RPC library from Sun, though there is a ti-RPC library here: http://nfsv4.bullopensource.org/doc/tirpc_rpcbind.php , if you use that library, you link with -ltirpc

You probably need svctcp_create or svcudp_create if you're using the standard RPC library included in glibc.

Community
  • 1
  • 1
nos
  • 223,662
  • 58
  • 417
  • 506
0

You probably have to link against the library when you create your program. If the library is called rpc, for example, this would be done by adding -lrpc to the compiler command line that creates the final executable.

sth
  • 222,467
  • 53
  • 283
  • 367