FAILED when compiling my project

TomasCZ
Posts: 39
Joined: Tue Apr 25, 2023 5:19 am

FAILED when compiling my project

Postby TomasCZ » Thu Dec 07, 2023 7:55 pm

Hi guys, pls, can someone help. I get this error when compiling my project:

Code: Select all

FAILED: BT_TUNER_SLAVE_AI.elf
cmd.exe /C "cd . && C:\Espressif\tools\xtensa-esp32-elf\esp-2022r1-11.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address  @CMakeFiles\BT_TUNER_SLAVE_AI.elf.rsp -o BT_TUNER_SLAVE_AI.elf  && cd ."
c:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.c.obj):(.literal.bt_task+0x18): undefined reference to `esp_bt_gap_is_connection'
c:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.c.obj):(.literal.bt_task+0x1c): undefined reference to `esp_read_data'
c:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.c.obj):(.literal.bt_task+0x20): undefined reference to `esp_send_data'
c:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.c.obj): in function `bt_task':
C:/Users/konec/ESP-IDF/BT_TUNER_SLAVE_AI/main/main.c:34: undefined reference to `esp_bt_gap_is_connection'
c:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Users/konec/ESP-IDF/BT_TUNER_SLAVE_AI/main/main.c:41: undefined reference to `esp_read_data'
c:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Users/konec/ESP-IDF/BT_TUNER_SLAVE_AI/main/main.c:55: undefined reference to `esp_send_data'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

 *  The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command ninja " terminated with exit code: 1.
The code is here:

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_log.h"

#include "esp_bt_device.h"
#include "esp_spp_api.h"

#include <string.h>
#include "nvs.h"
#include "nvs_flash.h"


#define TAG "BT_SLAVE"

// Deklarace funkcí
bool esp_bt_gap_is_connection();
int esp_read_data(uint8_t *buf, int size);
void esp_send_data(uint8_t *data, int size);

void bt_task(void *pvParameters) {
    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    esp_bt_controller_init(&bt_cfg);
    esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT);

    esp_bt_dev_set_device_name("ESP_SLAVE"); // Nastavení názvu zařízení

    vTaskDelay(1000 / portTICK_PERIOD_MS);

    while (1) {
        // Čekání na připojení
        if (!esp_bt_gap_is_connection()) {
            ESP_LOGI(TAG, "Čekám na připojení...");
            vTaskDelay(2000 / portTICK_PERIOD_MS);
            continue;
        }

        // Příjem dat ze spojení
        uint8_t buf[256];
        int len = esp_read_data(buf, sizeof(buf));
        if (len > 0) {
            buf[len] = '\0';
            ESP_LOGI(TAG, "Přijato: %s", buf);
        }

        // Odeslání dat na spojení
        char data_to_send[] = "Hello from Slave!";
        esp_send_data((uint8_t *)data_to_send, strlen(data_to_send));
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

void app_main() {
    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);

    esp_log_level_set(TAG, ESP_LOG_INFO);
    xTaskCreate(&bt_task, "bt_task", 2048, NULL, 5, NULL);
}
Pls, could someone help me ?

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

Re: FAILED when compiling my project

Postby MicroController » Thu Dec 07, 2023 10:08 pm

Don't forget to add the source file(s) which contain the implementations of

Code: Select all

bool esp_bt_gap_is_connection();
int esp_read_data(uint8_t *buf, int size);
void esp_send_data(uint8_t *data, int size);
to

Code: Select all

idf_component_register(SRCS "main.c" ...)
in your CMakeLists.txt.

Who is online

Users browsing this forum: Baidu [Spider] and 102 guests