linker cannot find a reference, but the compiler is happy

HEckardt
Posts: 31
Joined: Wed Aug 16, 2023 3:13 pm

linker cannot find a reference, but the compiler is happy

Postby HEckardt » Fri Feb 06, 2026 10:58 am

Dear Community,

I'm using the IDF ver. 5.5.2. with an ESP32.

I want to create a NAN publisher. I adapted the example (see "C:\Espressif\frameworks\esp-idf-v5.5.2\examples\wifi\wifi_aware\nan_publisher\main") to my project, include all the libs and add the

Code: Select all

    //Initialize NVS
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    initialise_wifi();

    wifi_nan_publish();

into my "main_app".

I thought all is OK, because the compiler is happy, when I build the project.

But the linker (I assume) is reporting errors:
C:\ESP32_Projects\Cellar2>idf.py build
Executing action: all (aliases: build)
Running ninja in directory C:\ESP32_Projects\Cellar2\build
Executing "ninja all"...
[1/1] C:\WINDOWS\system32\cmd.exe /C "cd /D C:\ESP32_Proje...C:/ESP32_Projects/Cellar2/build/bootloader/bootloader.bin"
Bootloader binary size 0x66c0 bytes. 0x940 bytes (8%) free.
[7/9] Linking CXX executable Cellar2.elf
FAILED: Cellar2.elf
C:\WINDOWS\system32\cmd.exe /C "cd . && C:\Espressif_5_5_Tools\Espressif\tools\xtensa-esp-elf\esp-14.2.0_20251107\xtensa-esp-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address -fno-builtin-memcpy -fno-builtin-memset -fno-builtin-bzero -fno-builtin-stpcpy -fno-builtin-strncpy -nostartfiles -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32=0 -Wl,--Map=C:/ESP32_Projects/Cellar2/build/Cellar2.map -Wl,--no-warn-rwx-segments -Wl,--orphan-handling=warn -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--warn-common -T esp32.peripherals.ld -T esp32.rom.ld -T esp32.rom.api.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.rom.libc-funcs.ld -T esp32.rom.newlib-reent-funcs.ld -T memory.ld -T sections.ld @CMakeFiles\Cellar2.elf.rsp -o Cellar2.elf && cd ."
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(Cellar2.c.obj):(.literal.nan_ndp_indication_event_handler+0x0): undefined reference to `esp_wifi_nan_datapath_resp'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(Cellar2.c.obj):(.literal.wifi_nan_publish+0x30): undefined reference to `esp_netif_create_default_wifi_nan'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(Cellar2.c.obj):(.literal.wifi_nan_publish+0x34): undefined reference to `esp_wifi_nan_start'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(Cellar2.c.obj):(.literal.wifi_nan_publish+0x38): undefined reference to `esp_wifi_nan_publish_service'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(Cellar2.c.obj):(.literal.wifi_nan_publish+0x3c): undefined reference to `esp_wifi_nan_send_message'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(Cellar2.c.obj): in function `nan_ndp_indication_event_handler':
C:/Espressif/frameworks/esp-idf-v5.5.2/examples/wifi/wifi_aware/nan_publisher/main/publisher_main.c:86:(.text.nan_ndp_indication_event_handler+0x2a): undefined reference to `esp_wifi_nan_datapath_resp'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(Cellar2.c.obj): in function `wifi_nan_publish':
C:/Espressif/frameworks/esp-idf-v5.5.2/examples/wifi/wifi_aware/nan_publisher/main/publisher_main.c:106:(.text.wifi_nan_publish+0x3d): undefined reference to `esp_netif_create_default_wifi_nan'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Espressif/frameworks/esp-idf-v5.5.2/examples/wifi/wifi_aware/nan_publisher/main/publisher_main.c:106:(.text.wifi_nan_publish+0x45): undefined reference to `esp_wifi_nan_start'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Espressif/frameworks/esp-idf-v5.5.2/examples/wifi/wifi_aware/nan_publisher/main/publisher_main.c:119:(.text.wifi_nan_publish+0xcc): undefined reference to `esp_wifi_nan_publish_service'
C:/Espressif_5_5_Tools/Espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Espressif/frameworks/esp-idf-v5.5.2/examples/wifi/wifi_aware/nan_publisher/main/publisher_main.c:149:(.text.wifi_nan_publish+0x162): undefined reference to `esp_wifi_nan_send_message'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the C:\ESP32_Projects\Cellar2\build\log\idf_py_stderr_output_13648 and C:\ESP32_Projects\Cellar2\build\log\idf_py_stdout_output_13648
There are some undefined references to functions, which are definetly defined in the includet libraries. When I build the example itself (in the example dir), all is OK.

What is to do to make the linker happy?

Thank you for support
Henry

MicroController
Posts: 2663
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: linker cannot find a reference, but the compiler is happy

Postby MicroController » Fri Feb 06, 2026 3:17 pm

Code: Select all

PRIV_REQUIRES esp_wifi
in your CMakeLists.txt?

Code: Select all

CONFIG_ESP_WIFI_NAN_SYNC_ENABLE=y
set?

HEckardt
Posts: 31
Joined: Wed Aug 16, 2023 3:13 pm

Re: linker cannot find a reference, but the compiler is happy

Postby HEckardt » Sat Feb 07, 2026 11:58 am

Hello MicroController,

thank you for your hints. The additional line in the "CMakeLists.txt" was not neccessary.
I could not find the entry "CONFIG_ESP_WIFI_NAN_SYNC_ENABLE" in "sdkconfig". It's possible that it existed in an earlier version.

But I changed in "menuconfig"
(Top) → Component config → Wi-Fi from [ ] WiFi Aware to [*] WiFi Aware.

In that case in "sdkconfig" changed:

# CONFIG_ESP_WIFI_NAN_ENABLE is not set

to

CONFIG_ESP_WIFI_NAN_ENABLE=y

and now the Linker is happy.

Thank you again for your support, which pointed in the right direction.

Greetings
Henry

Who is online

Users browsing this forum: Baidu [Spider], Barkrowler and 5 guests