问题
I would like to get rid of the warnings. When I compile the source code with
gcc -Wall -ansi -o test test.c
I get back
test.c: In function ‘main’:
test.c:12: warning: implicit declaration of function ‘getresuid’
test.c:14: warning: implicit declaration of function ‘seteuid’
When I compile it without -ansi switch
gcc -Wall -o test test.c
I see on the terminal
test.c: In function ‘main’:
test.c:12: warning: implicit declaration of function ‘getresuid’
I would like to use -ansi switch and get rid of warnings. How can I achieve my goal ?
/* this is the test.c */
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#define __USE_GNU 1
#define __USE_BSD 1
int main()
{
static uid_t euid, ruid, suid;
getresuid(&ruid, &euid, &suid);
seteuid(getuid());
return 0;
}
Environment:
CentOS 6.3 32-bit
gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
回答1:
getresuid()
and seteuid()
are GNU extension function, add
#define _GNU_SOURCE
before including all the headers, or add -D_GNU_SOURCE
in GCC options.
You shouldn't define __USE_GNU
macro directly, it's supposed to be used only internally in glibc.
回答2:
I solved by adding #include <unistd.h>
来源:https://stackoverflow.com/questions/19721810/warning-implicit-declaration-of-function-getresuid-and-seteuid