0

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)

3
  • The manual page you link to mentions gai_strerror but not gai_strerrorA. There exists a gai_strerrorA function in Windows, which is a Windows-specific extension to the standard gai_strerror function. Nov 23, 2020 at 8:52
  • @Someprogrammerdude Ah, that was it. How silly I am.. :) Thank you!
    – Chan Kim
    Nov 23, 2020 at 8:57
  • @Someprogrammerdude I changed gai_strerrorA to gai_strerror, now it's gone. (if you make your comment an answer, I'll choose it)
    – Chan Kim
    Nov 23, 2020 at 8:58

1 Answer 1

0

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.