我正在尝试编译一个包含对 getresuid
调用的函数。但是它会生成以下警告:
setuid.c:8:3: warning: implicit declaration of function 'getresuid' is invalid
in C99 [-Wimplicit-function-declaration]
getresuid(&ruid, &euid, &suid);
^
Undefined symbols for architecture x86_64:
"_getresuid", referenced from:
_main in setuid-ba46f8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
为什么会出现链接器错误,提示未找到架构 x86_64 的符号?如何让它链接成功?
如果有帮助,我原来的代码是:
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main() {
uid_t euid, ruid, suid;
getresuid(&ruid, &euid, &suid);
printf("EUID: %d, RUID: %d, SUID: %d\n", euid, ruid, suid);
return 0;
}
我正在尝试在 Mac OS X 10.10.2 (Yosemite) 上进行编译。
最佳答案
您需要在所有标题之前定义
#define _GNU_SOURCE
as getresuid
是一个 GNU 扩展函数。
关于c - getresuid 在 c99 中是否已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29888475/