开发者

Undefined reference to svc_create

开发者 https://www.devze.com 2023-04-10 16:47 出处:网络
My proble开发者_JAVA百科m is the following: I\'m trying to implement a C RPC example and I keep running into the following compiler error:

My proble开发者_JAVA百科m 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号