Chan Kim
Chan Kim

Reputation: 5959

I included necessary header file but get "error: gai_strerrorA was not declared in this scope", ubuntu16.04, g++ 5.5

I'm moving a code which runs on widows to linux now. Much part is using standard libraries but there are still some compile errors that I have to remove. Now, the error comes from this line

printf("[err] getaddrinfo: %s[%d] (%s, %d)\n", gai_strerrorA(ret), ret, server_addr, port);

and the error message is below.

g++ -Iinclude/ -Isource/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -std=c++11 -lm -lpthread -lrt -mavx -c source/sSocket2.cpp -o obj/sSocket2.o source/sSocket2.cpp: In member function bool sj::cSocket2::ConnectUDP(const char*, int, int, int, int):

source/sSocket2.cpp:125:68: error: gai_strerrorA was not declared in this scope printf("[err] getaddrinfo: %s[%d] (%s, %d)\n", gai_strerrorA(ret), ret, server_addr, port);

When I look up gai_strerrorA (https://linux.die.net/man/3/gai_strerror), it requires to #include <sys/types.h>, <sys/socket.h> and <netdb.h> so I added all those 3 files in the #include. But the error is still coming. What should I do? should I install some library files? (this is on ubuntu 16.04, g++ (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010)

Upvotes: 1

Views: 378

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409176

The gai_strerrorA function is a Windows-specific extension for "ASCII" strings (as opposed the gai_strerrorW for "Unicode" characters).

The plain POSIX standard function is just gai_strerror, without any character-specific suffix (Windows uses macros to define the suffix-less gai_strerror "function" depending on other macros).

Upvotes: 1

Related Questions