Help with compilation error ESP-IDF in VS code

nico13
Posts: 1
Joined: Thu May 25, 2023 3:50 pm

Help with compilation error ESP-IDF in VS code

Postby nico13 » Thu May 25, 2023 3:58 pm

So i have this error, that i should be simple, but can't manage to work around it.
I have my main project (wifi station). it works and compiles, it connects to wifi no problem.
So now i'm writing more code, and to have good order i cretead a functions.c and functions.h files, in a subfolder.
The problem is that if i just write the prototype in the .h and definitions of functions in .c, it won't find the function. If i write the definition of function directly on .h it works.

esp_zbo_functions.c

Code: Select all

#include "esp_zbo_functions.h"
#include "esp_log.h"

bool test = false;
void open_tcp_connection(void){
    if(!test){
       ESP_LOGI(DEBUG, "test"); 
       test = true;
    }
    
}
esp_zbo_functions.h

Code: Select all

#ifndef ESP_ZBO_FUNCTIONS_H
#define ESP_ZBO_FUBCTIONS_H



static const char *DEBUG = "DEBUG";


void open_tcp_connection(void);

#endif /* ESP_ZBO_FUBCTIONS_H */
esp_zbo_main.c (just main())

Code: Select all

void app_main(void)
{
    //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);
    ESP_LOGI(DEBUG, "pre wifi_init_sta");
    ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
    wifi_init_sta();
    ESP_LOGI(DEBUG, "pass wifi_init_sta");
    while(true){
        if(wifi_connected == true){
            open_tcp_connection();
        }
    }
}
error:
Generated C:/Users/Nico/Desktop/Proyectos/Cargadores_OCPP/esp32/esp_zbo/build/bootloader/bootloader.bin
[101/101] cmd.exe /C "cd /D C:\Users\Nico\Desktop\Proyectos\Cargadores_OCPP\esp32\esp_zbo\build\bootloader\esp-idf\esptool_py && C:\Users\Nico\.espressif\python_env\idf5.0_py3.8_env\Scripts\python.exe C:/Users/Nico/esp/esp-idf/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x1000 C:/Users/Nico/Desktop/Proyectos/Cargadores_OCPP/esp32/esp_zbo/build/bootloader/bootloader.bin"
Bootloader binary size 0x6700 bytes. 0x900 bytes (8%) free.
[841/843] Linking CXX executable esp_zbo.elf
FAILED: esp_zbo.elf
cmd.exe /C "cd . && C:\Users\Nico\.espressif\tools\xtensa-esp32-elf\esp-2022r1-11.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\esp_zbo.elf.rsp -o esp_zbo.elf && cd ."
c:/users/nico/.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(esp_zbo_main.c.obj):(.literal.app_main+0x24): undefined reference to `open_tcp_connection'
c:/users/nico/.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(esp_zbo_main.c.obj): in function `app_main':
C:/Users/Nico/Desktop/Proyectos/Cargadores_OCPP/esp32/esp_zbo/main/esp_zbo_main.c:165: undefined reference to `open_tcp_connection'
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.

ESP_Sprite
Posts: 9745
Joined: Thu Nov 26, 2015 4:08 am

Re: Help with compilation error ESP-IDF in VS code

Postby ESP_Sprite » Fri May 26, 2023 12:32 pm

Did you add esp_zbo_functions.c to CMakeFiles.txt?

Who is online

Users browsing this forum: ignisuti and 73 guests