HaxeFoundation/hashlink

Warnings when compiling mysql module (implicit declaration of function `gethostbyname_r`)

IceDragon200 opened this issue · 3 comments

An Arch Linux reported a build error regarding the gethostname_r function call

cc -Wall -O3 -I src -std=c11 -D LIBHL_EXPORTS -m64 -fPIC -pthread -fno-omit-frame-pointer -I/usr/include/mbedtls2 -o libs/mysql/socket.o -c libs/mysql/socket.c
libs/mysql/socket.c: In function ‘phost_resolve’:
libs/mysql/socket.c:130:17: warning: implicit declaration of function ‘gethostbyname_r’; did you mean ‘gethostbyname’? [-Wimplicit-function-declaration]
  130 |                 gethostbyname_r(host,&hbase,buf,1024,&h,&errcode);
      |                 ^~~~~~~~~~~~~~~
      |                 gethostbyname
libs/mysql/my_api.c: In function ‘mp_real_connect’:
libs/mysql/my_api.c:149:43: warning: implicit declaration of function ‘strdup’; did you mean ‘strcmp’? [-Wimplicit-function-declaration]
  149 |                 m->infos.server_version = strdup(myp_read_string(p));
      |                                           ^~~~~~
      |                                           strcmp
libs/mysql/my_api.c:149:41: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  149 |                 m->infos.server_version = strdup(myp_read_string(p));
      |

I was able to compile from scratch without issue, but the warnings were still present, I'm unsure if those warnings were always there and could be ignored, or if they spelled a much worse problem underneath.

I'm not familiar with the inner workings of this so I'm leaving this issue here for someone much smarter than me to figure it out.

However at a glance gethostbyname_r is present in the netdb.h header, so it should technically be fine, but it's locked behind a __USE_MISC definition, not entirely sure if it should be set manually or requires additional insight.

EDIT:

  • Did some digging a bit, __USE_MISC is an internal feature flag, it cannot and should not be set externally, instead one must alert the compile to use the _GNU_SOURCE branches (which will enable the _DEFAULT_SOURCE, which will in turn enable the __USE_MISC which will in turn make the gethostbyname_r and other related functions available), one could also just define _DEFAULT_SOURCE directly to lower the footprint (however once again I am quite rusty on my C knowledge as to the correct way to do this).

Related

Should already be fixed by #686
The warnings have become errors with GCC 14.

Any chance of a new release with the patches?

I can always whip up a patch file on my side based on your PR otherwise.

Okay this has been resolved with some patches, thanks for the help @Apprentice-Alchemist