我试图编译一个包含调用getresuid
的函数。然而,它会生成以下警告:在c99中被弃用吗?
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(优胜美地)。
直接的答案是 “否;'getresuid()'根本就不是C99的一部分 - 2008年也不POSIX(2013年)的”。所以要使用它,你必须使用特定于平台的扩展。你不需要'#include'在你的代码中。你的代码在Ubuntu 14.04上编译OK。你在使用哪个版本的Linux? –
我认为C99禁止隐式声明,而不是'getresuid()',这会导致混淆。 – myaut
@Jonathan Leffler:Mac OS 10.10.2?对不起,这可能是一个愚蠢的问题,但你需要什么样的扩展(以及哪里可以找到引用)? – lingz