c - getresuid 在 c99 中是否已弃用?

标签 c linux macos c99 setuid

我正在尝试编译一个包含对 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/

相关文章:

c - MAP_ANON 和 MAP_ANONYMOUS 都未在 C 中为 sys/mmap 声明

c - 多项式回归c代码

Swift - 在一行代码中完成文本字段字符串检查中的数字

c++ - 在 Mac OSX 中替代 --no-undefined

c - 如何读取文本文件中的逗号分隔行并将其字段插入到结构指针数组中?

c - 运行此代码时显示段错误错误

linux - 将文件从一个目录递归复制到另一个目录会导致一个目录中的更改也会反射(reflect)在另一个目录文件中吗?

linux - 有没有办法让 Splint 或类似的静态检查器与 Linux 内核模块一起工作?

用于 Linux 的 RegEx 和 grep

python - 属性错误: type object 'Callable' has no attribute '_abc_registry'