EDPIDF DHT sensor

ESPIDF
Though i have installed the library i am getting this issue

Scanning dependencies…
Dependency Graph
|-- dht_espidf
Building in release mode
Linking .pio\build\esp32doit-devkit-v1\bootloader.elf
Linking .pio\build\esp32doit-devkit-v1\firmware.elf
c:/users/dhung/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/12.2.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32doit-devkit-v1\src\main.o:(.literal.app_main+0x10): undefined reference to read_dht_sensor_data(gpio_num_t, dht_type_t, dht_reading*)' c:/users/dhung/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/12.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32doit-devkit-v1\src\main.o: in function app_main’:
D:\program\vscode\platform.io\DTH_SensorTest/src/main.cpp:15: undefined reference to `read_dht_sensor_data(gpio_num_t, dht_type_t, dht_reading*)’
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32doit-devkit-v1\firmware.elf] Error 1

Library github link : GitHub - infincia/dht_espidf: An ESP IDF component for the DHT11/22 humidity and temperature sensor family.

main.cpp
#include <stdio.h>
#include <string.h>
#include “freertos/FreeRTOS.h”
#include “freertos/task.h”
#include “esp_log.h”
#include “dht_espidf.h”

#define DHT_PIN GPIO_NUM_4

struct dht_reading dht_data{};
static const char *TAG = “Chamber1_Master”;

extern “C” void app_main() {
while (true) {
dht_result_t res = read_dht_sensor_data(DHT_PIN, DHT11, &dht_data);
if (res != DHT_OK) {
ESP_LOGI(TAG, “DHT sensor reading failed”);
continue;
}
float temperature = dht_data.temperature;
float humidity = dht_data.humidity;

    ESP_LOGI(TAG, "Temperature: %f, Humidity: %f", temperature, humidity);
    vTaskDelay(pdMS_TO_TICKS(2000));  // Delay for 2 seconds
}

}

Oh oh. Mixing main.cpp (C++) with dht_espidf.c (C) without declaring all functions in the dht_espidf.h as extern "C"? Due to name mangling, the C++ code won’t find the C functions then.

You need to apply this idiom

#ifdef __cplusplus
extern "C" {
#endif

<ALL FUNCTIONS AND VARIABLES HERE>

#ifdef __cplusplus
}
#endif

in the dht_espidf.h file, as seen e.g. here.

Or, easy mode: Rename dht_espidf.c to dht_espidf.cpp.

Thank-you for the idea,it worked👍