c - 对 svc_create 的 undefined reference

标签 c gcc compiler-construction compiler-errors rpc

我的问题如下:我正在尝试实现一个 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_createsvcudp_create

关于c - 对 svc_create 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7626651/

相关文章:

c++ - 如何正确定义C++类析构函数并将其链接到主文件?

python - 加速已编译的 python 程序?

c - C语言中的150位数字乘法

c - 在&#f;和printf&格式说明符中的用法

C语言枚举数据类型?

c# - 在 C# 中的编译时检查字符串格式

c++ - 程序中的编译器信息

C - 如何比较2个字符串的索引?

c - gcc : ‘asm’ operand has impossible constraints 中的扩展 asm

scanf 格式字符串中的 "%.70s"会导致意外行为吗?