esp-idf icon indicating copy to clipboard operation
esp-idf copied to clipboard

undefined reference to `if_nametoindex' (IDFGH-12575)

Open AxelLin opened this issue 1 year ago • 1 comments

Answers checklist.

  • [X] I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • [X] I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • [X] I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.1.3-416-gd23b7a0361

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

What is the expected behavior?

if_nametoindex() should pass compilation.

What is the actual behavior?

compile error: undefined reference to `if_nametoindex'

Steps to reproduce.

Follow https://docs.espressif.com/projects/esp-idf/zh_CN/v5.1.2/esp32/api-reference/kconfig.html#config-lwip-netif-api to set CONFIG_LWIP_NETIF_API=y.

Add below code and compile: int rc = if_nametoindex("sta0");

Then got compile error: undefined reference to `if_nametoindex'

Build or installation Logs.

No response

More Information.

No response

AxelLin avatar Apr 10 '24 03:04 AxelLin

Hi @AxelLin, Thanks for bringing this issue to our attention. Enabling CONFIG_LWIP_NETIF_API doesn't really enable if_nametoindex() api. As a result examples/protocols/sockets/tcp_client_multi_net also doesn't work with CONFIG_LWIP_NETIF_API enabled. This will be fixed in a future release.

For a workaround you can use lwip_if_nametoindex() instead of if_nametoindex().

abhik-roy85 avatar Apr 16 '24 12:04 abhik-roy85