2011-10-02 130 views
1

我的问题是这样的:我想实现一个C RPC例子,我一直运行到以下编译器错误:未定义参考svc_create

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 

我的代码:

#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; 
} 

我真的不知道如何解决这个问题。手册页和我研究过的所有例子都只是说包含rpc/rpc.h,但它似乎并不奏效。我正在编译

gcc -Wall -c 
+0

什么是您的操作系统,以及您要遵循的示例是什么操作系统? – Mat

+0

我使用的是Ubuntu 11.04。这些例子是针对linux。 – Tudor

+0

奇怪的是,我不认为API存在于Linux上(我认为这是Sun RPC)。链接到这个例子? – Mat

回答

2

在libc中linux上没有这样的函数svc_create。请参阅rpc的联机帮助页。您的指南正在使用Solaris和其他unix的传输无关(ti)RPC库。有关Linux的RPC指南,请参阅this问题。

Linux中的RPC库是基于一个稍微不同的RPC库比Sun的TI-RPC库,但有一个TI-RPC库的位置:http://nfsv4.bullopensource.org/doc/tirpc_rpcbind.php,如果你使用该库,你-ltirpc

链接

如果您使用glibc中包含的标准RPC库,则可能需要svctcp_createsvcudp_create

+0

你说得对。我的错。我没有使用正确的功能。 :( – Tudor

0

当您创建程序时,您可能需要链接库。例如,如果该库名为rpc,则可以通过将-lrpc添加到创建最终可执行文件的编译器命令行来完成。