lingz lingz - 2 years ago 160
C Question

Is getresuid deprecated in c99?

I'm trying to compile a function containing a call to

. However it generates the following warning:

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

Why is there a linker error saying symbol not found for architecture x86_64? How do you get it to successfully link?

If it helps, my original code was:

#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;

I'm trying to compile on Mac OS X 10.10.2 (Yosemite).

Answer Source

You need to define before all the headers

#define _GNU_SOURCE

as getresuid is a GNU extension function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download