Параметр getnameinfo и gcc -std = c17 возвращает ошибку: «неявное объявление функции getnameinfo» [закрыто]
Если я скомпилирую приложение с опцией -std = c17
gcc -std=c17 -Wall -Wpedantic -Werror main.c -o main
Я получаю ошибку «неявное объявление». Если я удалю -std = c17, все будет хорошо.
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
int main(void) {
struct sockaddr_in sa;
char node[NI_MAXHOST];
memset(&sa, 0, sizeof sa);
sa.sin_family = AF_INET;
inet_pton(AF_INET, "8.8.8.8", &sa.sin_addr);
int res = getnameinfo((struct sockaddr*)&sa, sizeof(sa),
node, sizeof(node),
NULL, 0, NI_NAMEREQD);
if (res) {
printf("error: %d\n", res);
printf("%s\n", gai_strerror(res));
}
else
printf("node=%s\n", node);
return 0;
}
ain.c: In function ‘main’:
main.c:9:15: error: ‘NI_MAXHOST’ undeclared (first use in this function)
9 | char node[NI_MAXHOST];
| ^~~~~~~~~~
main.c:9:15: note: each undeclared identifier is reported only once for each function it appears in
main.c:17:15: warning: implicit declaration of function ‘getnameinfo’ [-Wimplicit-function-declaration]
17 | int res = getnameinfo((struct sockaddr*)&sa, sizeof(sa),
| ^~~~~~~~~~~
main.c:19:36: error: ‘NI_NAMEREQD’ undeclared (first use in this function)
19 | NULL, 0, NI_NAMEREQD);
| ^~~~~~~~~~~
main.c:23:24: warning: implicit declaration of function ‘gai_strerror’; did you mean ‘strerror’? [-Wimplicit-function-declaration]
23 | printf("%s\n", gai_strerror(res));
| ^~~~~~~~~~~~
| strerror
main.c:23:18: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
23 | printf("%s\n", gai_strerror(res));
| ~^ ~~~~~~~~~~~~~~~~~
| | |
| | int
| char *
| %d
main.c:9:10: warning: unused variable ‘node’ [-Wunused-variable]
9 | char node[NI_MAXHOST];
| ^~~~
Если я остановлю компиляцию после предварительной обработки (
gcc
с опцией
-E
) Я вижу это
extern int getnameinfo()
также отсутствует в сгенерированных
.o
файл.
Я не понимаю почему.