Reputation: 69
I want to use function grantpt in my program. I include its header file <stdlib.h>
, but the compiler still give me the warning: implicit declaration of grantpt
, which means it cound't find the declaration in stdlib.h
. I grep
the header file and find the declaration:
stdlib.h:920:extern int grantpt (int __fd) __THROW;
And my glibc version is 2.17, the official manual says this function is included since version 2.1.
Here is my test program:
#include <stdio.h>
#include <stdlib.h>
typedef unsigned long u_l;
int main(){
int errno = grantpt(1);
printf("errno = %d\n", errno);
return 0;
}
Thanks a lot!
Upvotes: 0
Views: 1557
Reputation: 27230
#define _XOPEN_SOURCE
#include <stdlib.h>
#include <stdio.h>
//#include<sys/poll.h>
typedef unsigned long u_l;
int main()
{
int errno = grantpt(1);
printf("errno = %d\n", errno);
return 0;
}
This code compiles without that warning
See Man page clearly says that you need to define _XOPEN_SOURCE
before including stdlib.h
for accessing grantpt()
Upvotes: 2