Compile errors when creating multiple cpp files

djorr5
Posts: 16
Joined: Fri Nov 17, 2023 4:12 am

Compile errors when creating multiple cpp files

Postby djorr5 » Tue May 21, 2024 2:44 am

I know I am doing something stupid here but I can't figure out what. Basically I have IDF 5.1.3 and ESP Zigbee in a project. When I had it all in 1 .c and 1 .h file I could compile everything without any issues and it worked. However as the project has grown in size I have moved the functions etc to different files to make it simpler to follow. But now when I compile (I am doing inside ESP-IDF Powershell) I get random errors that I wasn't getting before. As an example, I get this error:

Code: Select all

error: invalid conversion from 'uint32_t' {aka 'long unsigned int'} to 'esp_zb_app_signal_type_t' [-fpermissive]  353 |     esp_zb_app_signal_type_t sig_type = *p_sg_p;
But if I go to main.cpp, where this error comes from, it is the exact same code from the project that compiles correctly (i.e. the single file project)

Doesn't compile:

Code: Select all

void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
{
    uint32_t *p_sg_p = signal_struct->p_app_signal;
    esp_err_t err_status = signal_struct->esp_err_status;
    esp_zb_app_signal_type_t sig_type = *p_sg_p;
    esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL;
Does compile:

Code: Select all

void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
{
    uint32_t *p_sg_p = signal_struct->p_app_signal;
    esp_err_t err_status = signal_struct->esp_err_status;
    esp_zb_app_signal_type_t sig_type = *p_sg_p;
    esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL;
  
when I follow the uint32_t definition in the project that doesn't compile it is picking up a define from esp_wifi_crypto_types.h

Code: Select all

typedef uint32_t (*esp_crc32_le_t)(uint32_t crc, uint8_t const *buf, uint32_t len);
but I haven't added this .h file. In the project that does compile is isn't picking up this define. I don't believe that I have added any additional .h files that should be causing this.

Have I stuffed up somewhere and it is bringing in additional header files that is causing these compile issues?

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

Re: Compile errors when creating multiple cpp files

Postby MicroController » Tue May 21, 2024 12:22 pm

C does automatic conversion between integer types and enums, C++ does not. In C++ you need an explicit cast to be able to assign the uint32_t value *p_sg_p to esp_zb_app_signal_type_t sig_type.

Btw, uint32_t comes from <stdint.h>, or <cstdint>.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 88 guests