Skip to content

[Bug] Implicit declaration of function getaddrinfo and freeaddrinfo when compiling #25540

@tuupola

Description

@tuupola

Describe the bug

With some of the targets compilation fails with two implicit declaration of function errors. For example:

$ make clean
$ make micoair_h743-v2_default -j8
...
<path/to>/PX4-Autopilot/src/modules/uxrce_dds_client/Micro-XRCE-DDS-Client/src/c/profile/transport/ip/udp/udp_transport_posix.c: In function 'uxr_init_udp_platform':
<path/to>/PX4-Autopilot/src/modules/uxrce_dds_client/Micro-XRCE-DDS-Client/src/c/profile/transport/ip/udp/udp_transport_posix.c:46:18: error: implicit declaration of function 'getaddrinfo' [-Wimplicit-function-declaration]
   46 |         if (0 == getaddrinfo(ip, port, &hints, &result))
      |                  ^~~~~~~~~~~
<path/to>/PX4-Autopilot/src/modules/uxrce_dds_client/Micro-XRCE-DDS-Client/src/c/profile/transport/ip/udp/udp_transport_posix.c:57:13: error: implicit declaration of function 'freeaddrinfo' [-Wimplicit-function-declaration]
   57 |             freeaddrinfo(result);
      |             ^~~~~~~~~~~~

Both getaddrinfo() and freeaddrinfo() function require NuttX with NETDB support to be enabled.

include/netdb.h#L286-L296

Which defaults to false.

libs/libc/netdb/Kconfig#L6-L8

I though the problem could be fixed adding CONFIG_LIBC_NETDB=y to nsh/defconfig for the given board. This does not work because the KConfig file does not include prompt for CONFIG_LIBC_NETDB.

Workaround is to enable a feature such as CONFIG_NETDB_HOSTFILE=y which then automatically sets CONFIG_LIBC_NETDB=y and compiling then succeeds.

libs/libc/netdb/Kconfig#L33-L36

Or if you are not using ROS you could just disable the uxrce_dds_client module with:

CONFIG_MODULES_UXRCE_DDS_CLIENT=n

I have two questions.

  1. Is nsh/defconfig file the correct place to fix the problem?

  2. Should netdb/Kconfig be patched so that directly setting CONFIG_LIBC_NETDB=y via nsh/defconfig would work?

To Reproduce

$ cd PX4-Autopilot
$ make clean
$ make micoair_h743-v2_default -j8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions