gpt4 book ai didi

linux - 在 rpc 中登录的用户数

转载 作者:IT王子 更新时间:2023-10-29 00:46:29 25 4
gpt4 key购买 nike

我是 rpc 的新手,即我处于学习阶段,我想找出从以下程序登录的用户数我像这样编译“cc samrpc.c -lrpcsvc”但是它显示的错误和警告是

     samrpc.c: In function ‘main’:
samrpc.c:9:1: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
samrpc.c:13:1: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
/tmp/ccxyIUNJ.o: In function `main':
samrpc.c:(.text+0x51): undefined reference to `rnusers'
collect2: error: ld returned 1 exit status

你能详细告诉我如何编译这个程序吗?我需要什么要求?注意:samrpc.c是程序名我的程序在下面

 #include <stdio.h>
int main(argc, argv)
int argc;
char **argv;
{
int num;
if (argc != 2) {
fprintf(stderr, "usage: rnusers hostname\n");
exit(1);
}
if ((num = rnusers(argv[1])) < 0) {
fprintf(stderr, "error: rnusers\n");
exit(-1);
}
printf("%d users on %s\n", num, argv[1]);
return 0;
}

最佳答案

检查你的代码

ld returned 1 exit status means you have undefined reference to your main function Due to which linker doesn't find a entry point to program

In you code main has not been defined properly your run time argument too have not been passed properly

#include <stdio.h>
#include<process.h>
int main(int argc,char ** argv)
{
int num;
if (argc != 2) {
fprintf(stderr, "usage: rnusers hostname\n");
exit(1);
}
if ((num = rnusers(argv[1])) < 0) {
fprintf(stderr, "error: rnusers\n");
exit(-1);
}
printf("%d users on %s\n", num, argv[1]);
return 0;
}

正确定义main,它应该可以工作

关于linux - 在 rpc 中登录的用户数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14535946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com