我的问题如下:我正在尝试实现一个 C RPC 示例,但我一直遇到以下编译器错误:
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
最佳答案
libc中没有linux上的svc_create
这样的函数。请参阅 rpc 的联机帮助页。您的指南使用的是 Solaris 和其他 unix 的传输独立 (ti) RPC 库。参见 this Linux 的 RPC 指南问题。
Linux 中的 RPC 库基于与 Sun 的 ti-RPC 库略有不同的 RPC 库,尽管这里有一个 ti-RPC 库:http://nfsv4.bullopensource.org/doc/tirpc_rpcbind.php , 如果你使用那个库,你链接 -ltirpc
如果您使用 glibc 中包含的标准 RPC 库,您可能需要 svctcp_create
或 svcudp_create
。
关于c - 对 svc_create 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7626651/