Undefined reference to espressif function

Seems like this is a common problem lately so I decided to wait a bit. I was nicely surprised to see that 1.9.0 of the ESPRESSIF platform was just released. Unfortunately the problem persists.

I keep getting an undefined reference error when linking the hmac_sha1 function. My project references the wpa2 functions of esp-idf and even the sntp lwip app which the linker has no problems with.

As far as I can tell I’m using the latest of everything under the VS Code IDE.

Any suggestions?

Not reproducible.


#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include <crypto/sha1.h>

void app_main()
    printf("Hello world!\n");

    int ret = hmac_sha1(NULL, 0, NULL, 0, NULL);
    printf("ret %d\n", ret);

    for (int i = 10; i >= 0; i--) {
        printf("Restarting in %d seconds...\n", i);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    printf("Restarting now.\n");


platform = espressif32
board = heltec_wifi_kit_32
framework = espidf


DATA:    [          ]   4.2% (used 13764 bytes from 327680 bytes)
PROGRAM: [==        ]  16.2% (used 170329 bytes from 1048576 bytes)
=============== [SUCCESS] Took 12.84 seconds ===============

I’ll need to see a minimal project which reproduces the problem you have from you now.

Thank you for the reply. It really helped get me unstuck.

The problem is that I’m programming in C++ but some the esp-idf source files do not appropriately apply ‘extern “C”’ to their definitions. In my case, the function hmac_sha1() lacks the extern “C” when my C++ code references it. I guess it went unnoticed since it is a sub-component of the wpa_supplicant code that usually would not be referenced directly by the application.

The solution is simply to wrap the “for C-only” header like this:

extern “C” {

The issue can be replicated by renaming the main.c file to main.cpp.