gcc g++编译时警告:"xxxx" 将随后被初始化_解决方法

本文探讨了GCC++编译器在编译过程中出现的一种特定警告:xxxx将随后被初始化的问题。此警告通常发生在使用初始化列表的构造函数中,当成员变量的初始化顺序与类定义中的顺序不匹配时产生。文章旨在帮助开发者理解这一警告产生的原因,并提供解决办法。

gcc g++编译时警告:  "xxxx" 将随后被初始化:

      

        这个问题的原因是在构造函数里,如果你在构造函数中初始化变量时,用的是初始化列表的方式,则初始化列表中的成员变量初始化顺序要和类定义时的变量顺序一致。



17:51:41 **** Incremental Build of configuration Debug for project TIM_Servo **** make -j8 all arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/main.o" ../Core/Src/main.c: In function 'main': ../Core/Src/main.c:113:55: error: macro "__HAL_TIM_SET_COMPARE" requires 3 arguments, but only 2 given 113 | __HAL_TIM_SET_COMPARE(&htim1,COUNT_MAX); | ^ In file included from ../Core/Inc/stm32f1xx_hal_conf.h:334, from ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h:29, from ../Core/Inc/main.h:30, from ../Core/Src/main.c:20: ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h:1394: note: macro "__HAL_TIM_SET_COMPARE" defined here 1394 | #define __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) \ | ../Core/Src/main.c:113:17: error: '__HAL_TIM_SET_COMPARE' undeclared (first use in this function) 113 | __HAL_TIM_SET_COMPARE(&htim1,COUNT_MAX); | ^~~~~~~~~~~~~~~~~~~~~ ../Core/Src/main.c:113:17: note: each undeclared identifier is reported only once for each function it appears in make: *** [Core/Src/subdir.mk:34: Core/Src/main.o] Error 1 "make -j8 all" terminated with exit code 2. Build might be incomplete. 17:51:43 Build Failed. 3 errors, 0 warnings. (took 1s.658ms) 怎么回事
最新发布
10-02
在使用STM32CubeIDE进行编译时,出现以下错误: D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/gpio.c:51:(.text.MX_GPIO_Init+0x72): undefined reference to `HAL_GPIO_WritePin' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/gpio.c:58:(.text.MX_GPIO_Init+0x98): undefined reference to `HAL_GPIO_Init' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Src/main.o: in function `main': D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/main.c:85:(.text.main+0x4): undefined reference to `HAL_Init' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/main.c:115:(.text.main+0x20): undefined reference to `HAL_UART_Receive_IT' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/main.c:126:(.text.main+0x3e): undefined reference to `HAL_UART_Transmit_IT' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Src/main.o: in function `SystemClock_Config': D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/main.c:162:(.text.SystemClock_Config+0x66): undefined reference to `HAL_RCC_OscConfig' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/main.c:174:(.text.SystemClock_Config+0x92): undefined reference to `HAL_RCC_ClockConfig' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/main.c:180:(.text.SystemClock_Config+0xae): undefined reference to `HAL_RCCEx_PeriphCLKConfig' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Src/stm32f0xx_it.o: in function `SysTick_Handler': D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/stm32f0xx_it.c:130:(.text.SysTick_Handler+0x4): undefined reference to `HAL_IncTick' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Src/stm32f0xx_it.o: in function `USART1_IRQHandler': D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/stm32f0xx_it.c:151:(.text.USART1_IRQHandler+0x8): undefined reference to `HAL_UART_IRQHandler' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Src/stm32f0xx_it.o: in function `USART2_IRQHandler': D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/stm32f0xx_it.c:165:(.text.USART2_IRQHandler+0x8): undefined reference to `HAL_UART_IRQHandler' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Src/usart.o: in function `MX_USART1_UART_Init': D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/usart.c:45:(.text.MX_USART1_UART_Init+0x46): undefined reference to `HAL_UART_Init' D:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Src/usart.o: in function `MX_USART2_UART_Init': D:/ST/STM32CubeIDE/workspace_1.18.1/F030/usart2comm/Debug/../Src/usart.c:66:(.text.MX_USART2_UART_Init+0x46): undefined reference to `HAL_UART_Init' collect2.exe: error: ld returned 1 exit status make: *** [makefile:63: usart2comm.elf] Error 1 "make -j12 all" terminated with exit code 2. Build might be incomplete. 15:08:20 Build Failed. 14 errors, 0 warnings. (took 5s.624ms)
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值