自建组件中LOGI出错

tommy.guo
Posts: 24
Joined: Mon Feb 14, 2022 8:09 am

自建组件中LOGI出错

Postby tommy.guo » Fri Apr 22, 2022 4:08 pm

在espidf的example里,复制了一个工程出来,自己添加了comments文件夹,将example中softAP代码添加到组件里。

Code: Select all

ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d",
                 MAC2STR(event->mac), event->aid);
这句编译时报错。
目录结构是:

Code: Select all

.
├── CMakeLists.txt
├── README.md
├── components
│   ├── README.md
│   ├── http_server
│   │   ├── CMakeLists.txt
│   │   ├── html
│   │   │   ├── jquery.min.js.gz
│   │   │   └── web.html.gz
│   │   ├── web_server.c
│   │   └── web_server.h
│   └── softAP
│       ├── CMakeLists.txt
│       ├── Kconfig.projbuild
│       ├── soft_ap.c
│       └── soft_ap.h
├── main
│   ├── CMakeLists.txt
│   ├── Kconfig.projbuild
│   ├── nmea_parser.c
│   ├── nmea_parser.h
│   └── nmea_parser_example_main.c
├── sdkconfig
└── sdkconfig.old

5 directories, 19 files
当components下只有softAP组件时能编译通过,添加了http_server组件就会报错。
具体报错如下:

Code: Select all

In file included from ../components/softAP/soft_ap.c:15:
../components/softAP/soft_ap.c: In function 'wifi_event_handler':
../components/softAP/soft_ap.c:44:33: error: expected ')' before 'MACSTR'
         ESP_LOGI(TAG, "station "MACSTR" join, AID=%d",
                                 ^~~~~~
/home/tommy/esp_s3/esp-idf/components/log/include/esp_log.h:281:79: note: in definition of macro 'LOG_FORMAT'
 #define LOG_FORMAT(letter, format)  LOG_COLOR_ ## letter #letter " (%u) %s: " format LOG_RESET_COLOR "\n"
                                                                               ^~~~~~
/home/tommy/esp_s3/esp-idf/components/log/include/esp_log.h:431:41: note: in expansion of macro 'ESP_LOG_LEVEL'
         if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
                                         ^~~~~~~~~~~~~
/home/tommy/esp_s3/esp-idf/components/log/include/esp_log.h:341:38: note: in expansion of macro 'ESP_LOG_LEVEL_LOCAL'
 #define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO,    tag, format, ##__VA_ARGS__)
                                      ^~~~~~~~~~~~~~~~~~~
../components/softAP/soft_ap.c:44:9: note: in expansion of macro 'ESP_LOGI'
         ESP_LOGI(TAG, "station "MACSTR" join, AID=%d",
         ^~~~~~~~
/home/tommy/esp_s3/esp-idf/components/log/include/esp_log.h:264:27: error: format '%u' expects a matching 'unsigned int' argument [-Werror=format=]
 #define LOG_COLOR(COLOR)  "\033[0;" COLOR "m"
                           ^~~~~~~~~
cmakelists.txt内容为:

Code: Select all

http_server下:
idf_component_register(SRCS "web_server.c"
                    INCLUDE_DIRS "."
                    EMBED_FILES "./html/web.html.gz" "./html/jquery.min.js.gz"
                    PRIV_REQUIRES 
                    nvs_flash
                    esp_http_server)

Code: Select all

softAP下:
idf_component_register(SRCS "soft_ap.c"
                    INCLUDE_DIRS "."
                    PRIV_REQUIRES 
                    nvs_flash
                    esp_http_server)
实在不太懂这个错误的来源,请有经验的大佬指点一下。

tommy.guo
Posts: 24
Joined: Mon Feb 14, 2022 8:09 am

Re: 自建组件中LOGI出错

Postby tommy.guo » Sat Apr 23, 2022 3:53 am

找到问题了,需要包含#include "esp_mac.h"

Who is online

Users browsing this forum: No registered users and 81 guests