Errors in esp_log while Compiling

sumati2000
Posts: 6
Joined: Tue Jan 09, 2024 8:12 pm

Errors in esp_log while Compiling

Postby sumati2000 » Thu Jun 27, 2024 2:22 pm

Hello,

I am using esp-idf extension on VsCode and was able to flash my board using the blink example. However, now, using a different code, I am getting errors in esp_log.h:

C:/Espressif/esp-idf-v5.2.2/components/log/include/esp_log.h:291:27: error: format '%d' expects argument of type 'int', but argument 6 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
291 | #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"

I am getting multiple format errors. Why would this be happening? Since these are libraries provided by ESP.

Is there a way I can remove "-Werror=format=" flag? Should I?

leschge
Posts: 37
Joined: Fri May 06, 2022 1:38 pm

Re: Errors in esp_log while Compiling

Postby leschge » Thu Jun 27, 2024 3:12 pm

uint32 (long int) must be printed with %ld. Instead of using compiler flags its better to adjust the failing %d formats.
I am using IDF 5.0.1 where there are no errors. So you shouldnt get any errors with newer versions.

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

Re: Errors in esp_log while Compiling

Postby MicroController » Thu Jun 27, 2024 3:31 pm

And if you don't want to bother with (platform-specific) integer formatting strings, you can #include <inttypes.h> and use the macros it provides, like

Code: Select all

ESP_LOGI(TAG, "u32 value = " PRIu32 ", s8 value = " PRId8 , my_uint32, my_int8);

sumati2000
Posts: 6
Joined: Tue Jan 09, 2024 8:12 pm

Re: Errors in esp_log while Compiling

Postby sumati2000 » Thu Jun 27, 2024 4:01 pm

@leschge I went ahead and changed all the errors manually and now I have "Linking CXX executable UVC-Copy.elf
FAILED: UVC-Copy.elf" error where UVC-Copy is my project name

Albybe
Posts: 10
Joined: Fri May 29, 2020 10:45 pm

Re: Errors in esp_log while Compiling

Postby Albybe » Tue Oct 15, 2024 3:22 am

Hi all,
I'm trying to compile a project started on ver 4.4 now using the 5.3.1 because I need to use the pre encrypted ota functionality
(I tried the cherry picking commit to ver 4.4 but ...I could not merge... errors).

I'm using Linux VsCodium with espressif extension, but I also checked compiling in the directory with . $HOME.../export.sh than idf.py flash monitor.... same errors.

Sure I'm a basic programmer, but

I have in my project these same multiple errors in files provided by espressif like for example esp_log.h

example:

/home/jazz/esp/esp-idf/components/log/include/esp_log_color.h:43:69: error: format '%d' expects argument of type 'int', but argument 7 has type 'int64_t' {aka 'long long int'} [-Werror=format=]
43 | #define LOG_ANSI_COLOR(TEXT_COLOR) "\033[" TEXT_COLOR "m"
| ^~~~~~~
/home/jazz/esp/esp-idf/components/log/include/esp_log_color.h:47:69: note: in expansion of macro 'LOG_ANSI_COLOR'
47 | #define LOG_ANSI_COLOR_REGULAR(COLOR) LOG_ANSI_COLOR(LOG_ANSI_COLOR_STYLE_RESET ";" COLOR)
| ^~~~~~~~~~~~~~

(they are like 50 errors in my all project).

I did not understand, or I made it wrong, or it does not work, adding the line to the CMakeLists.txt... I tried both CMakeLists.txt files because I did not knownn which one was the correct one (the one in the project_name dir or the one in the project_name/main dir).

I tried the #include <inttypes.h> and tried to change lines to the PRI things....... without success.

Many of the lines are part of MACROS like this one: esp_log_color.h so... how I apply the "PRI" changes to the macros ???

43 | #define LOG_ANSI_COLOR(TEXT_COLOR) "\033[" TEXT_COLOR "m"

What should I change to this line 43?? Or what should I change to that file... or... What should I change to the project to get rid of that error?

SO, is there a way to make it work? Can some good guy provide an example to correct the errors for example in the "esp_log_color.h"?

Or a detailed workaround guide for a dumb guy like me please?

Rellly I did not understood how to workaround this problem.

Thank you very much and I apologize for reopening this thread but it's 2 days I'm stuck in this project I need to finish (I only have to add OTA (encrypted) and it's ready... hardware is already ready.... pcb boards ready.... but I'm stuck on this :((((( )

Thank you very much, bye,
Albybe.

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

Re: Errors in esp_log while Compiling

Postby MicroController » Tue Oct 15, 2024 7:39 am

Albybe wrote:
Tue Oct 15, 2024 3:22 am
format '%d' expects argument of type 'int', but argument 7 has type 'int64_t' {aka 'long long int'} [-Werror=format=]
This error specifically indicates that, probably in your own code, there's some logging call like ESP_LOGx(TAG, "... %d ...", some_int64_value); and "%d" does not match a 64-bit int.
Check the ESP_LOGx calls in your code and make sure the format string specification matches the arguments.
One way to clean things up is to #include <inttypes.h> and use the PRI... macros like

Code: Select all

#include <inttypes.h>
...
ESP_LOGI(TAG, "32-bit unsigned: %" PRIu32 ", 64-bit signed: %" PRId64, some_uint32_value, some_int64_value);

Albybe
Posts: 10
Joined: Fri May 29, 2020 10:45 pm

Re: Errors in esp_log while Compiling

Postby Albybe » Tue Oct 15, 2024 2:54 pm

Hi, thanks for your reply,

two things I do not understand:

1) Lots of errors are not in my code but in esp-idf libraries.

2) How do I correct the macros? Es. How do I apply the PRIu32... example you provided to this line?

#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"

I have the error at the beginning just in this part "\033[0;" how do I modify it?

(and I got same exact errors in the espressif example https_mbedtls :( )

Thank you very much for helping me,
Albybe :)

Albybe
Posts: 10
Joined: Fri May 29, 2020 10:45 pm

Re: Errors in esp_log while Compiling

Postby Albybe » Tue Oct 15, 2024 9:56 pm

FOLLOW UP:

I swapped all
ESP_LOGx(TAG,
with
printf(

using linux "sed" command.

in the esp-idf directory and subdirs in all files.


Same thing for other logging errors in HIP_LOGx and similar logging functions I did not know the existence of.


Errors are detected in ESP_LOGx functions where "%u" is not present also!

The error talking about "%u" is present in "strings only logging" like this below string:

ESP_LOGE("This is a string with no variables");

And I get the "%u error" here?????????!?


So, I think the problem is the BUGGED LOGGING MECHANISM of espressif v5. Or... some other factors I can not understand/find.
(if someone demostrate that I'm wrong I will be happy! And if can help me resolve I will be very "thank you!!" :) )

I'm doing all this experiments on the https_mbedtls example that, like my project, do not compile for the ESP_LOGx %u errors...

So: why some other smaller project do compile even if they include the ESP_LOGx thing?

Now I'm trying to change Some others LOG function I do not understand that...

Bye

nopnop2002
Posts: 112
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: Errors in esp_log while Compiling

Postby nopnop2002 » Tue Oct 15, 2024 10:31 pm

> I think the problem is the BUGGED LOGGING MECHANISM of espressif v5

No.

If the format and variable type do not match in ESP_LOGx, ESP-IDF will display many errors.


However, the root cause is simply a mismatch between the format and variable type.

When building the code below, ESP-IDF displays an error with more than 20 lines.

Code: Select all

#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"

void app_main()
{
    int CoreID = xPortGetCoreID();
    ESP_LOGI("MAIN", "start CoreID=%s",CoreID);
    //ESP_LOGI("MAIN", "start CoreID=%d",CoreID);
}

If the format and variable type match, all errors will disappear.

Code: Select all

#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"

void app_main()
{
    int CoreID = xPortGetCoreID();
    //ESP_LOGI("MAIN", "start CoreID=%s",CoreID);
    ESP_LOGI("MAIN", "start CoreID=%d",CoreID);
}

The solution is as shown by MicroController.

Albybe
Posts: 10
Joined: Fri May 29, 2020 10:45 pm

Re: Errors in esp_log while Compiling

Postby Albybe » Tue Oct 15, 2024 11:06 pm

Thank you for help,

but, so what about this 109 line ?
(I wrote it because I already changed almost all ESP_LOGx in all esp-idf v5 with printf)


/home/jazz/esp/v5.3.1/esp-idf/components/hal/spi_hal.c:109:1: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
109 | ESP_LOGI(TAG, "This is only a string");
| ^


no INT no %u, no numbers here. It's a string, so it's a "pointer" maybe... but the error says "argument 4" while only 2 arguments are in this ESP_LOGI function :(

where is the "uint32_t" argument 4 provoking the error in that 109 line? I don't understand, probably I'm too dumb :(

Thanks,
Albybe
Last edited by Albybe on Tue Oct 15, 2024 11:28 pm, edited 1 time in total.

Who is online

Users browsing this forum: No registered users and 222 guests