component.mk 添加CFLAGS不生效

liangkongde
Posts: 1
Joined: Sat Sep 18, 2021 3:39 am

component.mk 添加CFLAGS不生效

Postby liangkongde » Thu Oct 14, 2021 10:00 am

问题:
我在执行idf.py build编译时遇到了报错error: missing braces around initializer [-Werror=missing-braces]。我搜索了解决方法,发现可以在component.mk上添加CFLAGS +=-Wno-missing-braces 将报错改为报警。我添加上了发现并没有起作用。最后我在CMakeLists.txt 上添加target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-missing-braces")得以解决。参考这个链接中的解决方法viewtopic.php?f=25&t=23244&p=83496&hili ... ces#p83496
想知道这为啥直接在compoment.mk添加CFLAGS不生效?
环境:
硬件环境:ESP32-WROVER-B芯片
软件环境:IDF 版本 v4.4-dev-2825-gb63ec47238
开发环境:
操作系统:Win10
IDE: VS Code

日志:
以下为idf.py build执行的日志,我是通过ccache这一段判断没有生效的。
  1. PS F:\Gooddisplay\GxEPD_HD\new\epdiy\examples\calendar_demo> idf.py build
  2. Executing action: all (aliases: build)
  3. Running ninja in directory f:\gooddisplay\gxepd_hd\new\epdiy\examples\calendar_demo\build
  4. Executing "ninja all"...
  5. [1/10] Performing build step for 'bootloader'
  6. [1/1] cmd.exe /C "cd /D F:\Gooddisplay\GxEPD_HD\new\epdiy\examples\calendar_demo\build\bootloader\esp-idf\esptool_py && C:\Users\liangkongde\.espressif\python_env\idf4.4_py3.6_env\Scripts\python.exe F:/ESP/esp-idf/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x1000 F:/Gooddisplay/GxEPD_HD/new/epdiy/examples/calendar_demo/build/bootloader/bootloader.bin"
  7. Bootloader binary size 0x6a10 bytes. 0x5f0 bytes (6%) free.
  8. [2/8] Building C object esp-idf/FlexLayout/CMakeFiles/__idf_FlexLayout.dir/FlexLayout.c.obj
  9. FAILED: esp-idf/FlexLayout/CMakeFiles/__idf_FlexLayout.dir/FlexLayout.c.obj
  10. ccache C:\Users\liangkongde\.espressif\tools\xtensa-esp32-elf\esp-2021r1-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc.exe  -Iconfig -I../components/FlexLayout/include -IF:/ESP/esp-idf/components/newlib/platform_include -IF:/ESP/esp-idf/components/freertos/include -IF:/ESP/esp-idf/components/freertos/port/xtensa/include -IF:/ESP/esp-idf/components/freertos/include/esp_additions -IF:/ESP/esp-idf/components/esp_hw_support/include -IF:/ESP/esp-idf/components/esp_hw_support/include/soc -IF:/ESP/esp-idf/components/esp_hw_support/include/soc/esp32 -IF:/ESP/esp-idf/components/esp_hw_support/port/esp32/. -IF:/ESP/esp-idf/components/heap/include -IF:/ESP/esp-idf/components/log/include -IF:/ESP/esp-idf/components/lwip/include/apps -IF:/ESP/esp-idf/components/lwip/include/apps/sntp -IF:/ESP/esp-idf/components/lwip/lwip/src/include -IF:/ESP/esp-idf/components/lwip/port/esp32/include -IF:/ESP/esp-idf/components/lwip/port/esp32/include/arch -IF:/ESP/esp-idf/components/soc/include -IF:/ESP/esp-idf/components/soc/esp32/. -IF:/ESP/esp-idf/components/soc/esp32/include -IF:/ESP/esp-idf/components/hal/esp32/include -IF:/ESP/esp-idf/components/hal/include -IF:/ESP/esp-idf/components/hal/platform_port/include -IF:/ESP/esp-idf/components/esp_rom/include -IF:/ESP/esp-idf/components/esp_rom/include/esp32 -IF:/ESP/esp-idf/components/esp_rom/esp32 -IF:/ESP/esp-idf/components/esp_common/include -IF:/ESP/esp-idf/components/esp_system/include -IF:/ESP/esp-idf/components/esp_system/port/soc -IF:/ESP/esp-idf/components/esp_system/port/public_compat -IF:/ESP/esp-idf/components/esp32/include -IF:/ESP/esp-idf/components/xtensa/include -IF:/ESP/esp-idf/components/xtensa/esp32/include -IF:/ESP/esp-idf/components/driver/include -IF:/ESP/esp-idf/components/driver/esp32/include -IF:/ESP/esp-idf/components/esp_pm/include -IF:/ESP/esp-idf/components/esp_ringbuf/include -IF:/ESP/esp-idf/components/efuse/include -IF:/ESP/esp-idf/components/efuse/esp32/include -IF:/ESP/esp-idf/components/vfs/include -IF:/ESP/esp-idf/components/esp_wifi/include -IF:/ESP/esp-idf/components/esp_event/include -IF:/ESP/esp-idf/components/esp_netif/include -IF:/ESP/esp-idf/components/esp_eth/include -IF:/ESP/esp-idf/components/tcpip_adapter/include -IF:/ESP/esp-idf/components/esp_phy/include -IF:/ESP/esp-idf/components/esp_phy/esp32/include -IF:/ESP/esp-idf/components/esp_ipc/include -IF:/ESP/esp-idf/components/app_trace/include -IF:/ESP/esp-idf/components/esp_timer/include -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw -O2 -fmacro-prefix-map=F:/Gooddisplay/GxEPD_HD/new/epdiy/examples/calendar_demo=. -fmacro-prefix-map=F:/ESP/esp-idf=IDF -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.4-dev-2825-gb63ec47238-dirty\" -DESP_PLATFORM -MD -MT esp-idf/FlexLayout/CMakeFiles/__idf_FlexLayout.dir/FlexLayout.c.obj -MF esp-idf\FlexLayout\CMakeFiles\__idf_FlexLayout.dir\FlexLayout.c.obj.d -o esp-idf/FlexLayout/CMakeFiles/__idf_FlexLayout.dir/FlexLayout.c.obj -c ../components/FlexLayout/FlexLayout.c
  11. ../components/FlexLayout/FlexLayout.c:29:32: error: missing braces around initializer [-Werror=missing-braces]
  12. #define FlexCacheSizeUndefined (FlexSize){ -1000, -1000 }
  13.                                ^
  14. ../components/FlexLayout/FlexLayout.c:240:28: note: in expansion of macro 'FlexCacheSizeUndefined'
  15.     .lastConstrainedSize = FlexCacheSizeUndefined,
  16.                            ^~~~~~~~~~~~~~~~~~~~~~
  17. ../components/FlexLayout/FlexLayout.c:202:41: error: missing braces around initializer [-Werror=missing-braces]
  18. static const FlexNode defaultFlexNode = {
  19.                                         ^
  20. ../components/FlexLayout/FlexLayout.c:241:1: warning: missing initializer for field 'lastSize' of 'FlexNode' {aka 'const struct FlexNode'} [-Wmissing-field-initializers]
  21. };
  22.  ^
  23. ../components/FlexLayout/FlexLayout.c:197:16: note: 'lastSize' declared here
  24.      FlexLength lastSize[2];
  25.                 ^~~~~~~~
  26. ../components/FlexLayout/FlexLayout.c: In function 'flex_markDirty':
  27. ../components/FlexLayout/FlexLayout.c:29:32: error: missing braces around initializer [-Werror=missing-braces]
  28.  #define FlexCacheSizeUndefined (FlexSize){ -1000, -1000 }
  29.                                 ^
  30. ../components/FlexLayout/FlexLayout.c:245:33: note: in expansion of macro 'FlexCacheSizeUndefined'
  31.      node->lastConstrainedSize = FlexCacheSizeUndefined;
  32.                                  ^~~~~~~~~~~~~~~~~~~~~~
  33. ../components/FlexLayout/FlexLayout.c: In function 'flex_measureNode':
  34. ../components/FlexLayout/FlexLayout.c:445:12: error: missing braces around initializer [-Werror=missing-braces]
  35.      return (FlexSize){0,0};
  36.             ^
  37.                        {  }
  38. ../components/FlexLayout/FlexLayout.c: In function 'flex_layoutInternal':
  39. ../components/FlexLayout/FlexLayout.c:468:29: error: missing braces around initializer [-Werror=missing-braces]
  40.      FlexSize resolvedSize = {resolvedWidth, resolvedHeight};
  41.                              ^
  42.                               {                            }
  43. ../components/FlexLayout/FlexLayout.c:469:34: error: missing braces around initializer [-Werror=missing-braces]
  44.      FlexSize resolvedInnerSize = {
  45.                                   ^
  46. ../components/FlexLayout/FlexLayout.c:29:32: error: missing braces around initializer [-Werror=missing-braces]
  47.  #define FlexCacheSizeUndefined (FlexSize){ -1000, -1000 }
  48.                                 ^
  49. ../components/FlexLayout/FlexLayout.c:501:37: note: in expansion of macro 'FlexCacheSizeUndefined'
  50.          node->lastConstrainedSize = FlexCacheSizeUndefined;
  51. ../components/FlexLayout/FlexLayout.c:558:35: error: missing braces around initializer [-Werror=missing-braces]
  52.      FlexSize resolvedMarginSize = {resolvedMarginWidth, resolvedMarginHeight};
  53.                                    ^
  54.                                     {                                        }
  55. ../components/FlexLayout/FlexLayout.c:559:36: error: missing braces around initializer [-Werror=missing-braces]
  56.                                     ^
  57.                                      {                                          }
  58. ../components/FlexLayout/FlexLayout.c:806:43: warning: comparison is always false due to limited range of data type [-Wtype-limits]                         if (violations[j] < 0) {
  59.                                           ^
  60. ../components/FlexLayout/FlexLayout.c:1209:15: warning: unused variable 'bottom' [-Wunused-variable]
  61.         float bottom = item->result.position[FLEX_TOP] + item->result.size[FLEX_HEIGHT];
  62.                ^~~~~~
  63. ../components/FlexLayout/FlexLayout.c:1208:15: warning: unused variable 'right' [-Wunused-variable]
  64.          float right = item->result.position[FLEX_LEFT] + item->result.size[FLEX_WIDTH];
  65.                ^~~~~
  66. cc1.exe: some warnings being treated as errors
  67. ninja: build stopped: subcommand failed.
  68. ninja failed with exit code 1
组件的CMakeLists.txt文件:
  1. idf_component_register(SRCS "FlexLayout.c"
  2.                     INCLUDE_DIRS "include")
componet.mk文件:
  1. #
  2. # "main" pseudo-component makefile.
  3. #
  4. # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
  5. CFLAGS +=-Wno-missing-braces
  6. CPPFLAGS +=-Wno-missing-braces
报错的文件只写了一部分:
  1. typedef union {
  2.     struct {
  3.         float width;
  4.         float height;
  5.     };
  6.     float size[2];
  7. } FlexSize;
  8.  
  9. #define FlexCacheSizeUndefined (FlexSize){ -1000, -1000 }
  10.  
如果在组件的CMakeLists.txt文件设置上target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-missing-braces")是正常的。
附件为编译正常和编译失败的完整日志:
build_right_log.txt
(14.98 KiB) Downloaded 272 times
build_error_log.txt
(17.39 KiB) Downloaded 258 times

Who is online

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