ST意法半导体
直播中

李雪

8年用户 1003经验值
私信 关注
[问答]

stm32 vscode extension无法编译成功怎么解决?

正在生成文件夹: C:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/build/Debug [main] 正在配置项目: HK_STM32_PLC_vscode [proc] 执行命令: F:programsSTM32CubeCLT_1.16.0CMakebincmake.EXE -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=C:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/cmake/gcc-arm-none-eabi.cmake -SC:/Users/Administrator/Desktop/HK_STM32_PLC_vscode -BC:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/build/Debug -G Ninja[cmake] Build type: Debug[cmake] -- Configuring done (0.1s)[cmake] -- Generating done (0.0s)[cmake] -- Build files have been written to: C:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/build/Debug[build] 正在启动生成[proc] 执行命令: F:programsSTM32CubeCLT_1.16.0CMakebincmake.EXE --build C:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/build/Debug --[build] [1/1] Linking C executable HK_STM32_PLC.elf[build] FAILED: HK_STM32_PLC.elf [build] C:Windowssystem32cmd.exe /C "cd . && F:programsSTM32CubeCLT_1.16.0GNU-tools-for-STM32binarm-none-eabi-gcc.exe -mcpu=cortex-m3  -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections -O0 -g3 -mcpu=cortex-m3  -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections -O0 -g3 -g -mcpu=cortex-m3  -T "C:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/STM32F103VETx_FLASH.ld" --specs=nano.specs -Wl,-Map=HK_STM32_PLC.map -Wl,--gc-sections -Wl,--start-group -lc -lm -Wl,--end-group -Wl,--print-memory-usage  CMakeFiles/HK_STM32_PLC.dir/Core/Src/main.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/gpio.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/freertos.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/adc.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/dac.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/dma.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/tim.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/usart.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/stm32f1xx_it.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/stm32f1xx_hal_msp.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/stm32f1xx_hal_timebase_tim.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dac.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dac_ex.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c.obj CMakeFiles/HK_STM32_PLC.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/system_stm32f1xx.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/croutine.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/list.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/queue.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/tasks.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/timers.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c.obj CMakeFiles/HK_STM32_PLC.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/sysmem.c.obj CMakeFiles/HK_STM32_PLC.dir/Core/Src/syscalls.c.obj CMakeFiles/HK_STM32_PLC.dir/startup_stm32f103xe.s.obj -o HK_STM32_PLC.elf   && cd ."[build] F:/programs/STM32CubeCLT_1.16.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe:C:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/STM32F103VETx_FLASH.ld:56: syntax error[build] collect2.exe: error: ld returned 1 exit status[build] ninja: build stopped: subcommand failed.[proc] 命令“F:programsSTM32CubeCLT_1.16.0CMakebincmake.EXE --build C:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/build/Debug --”已退出,代码为 1[driver] 生成完毕: 00:00:00.110[build] 生成已完成,退出代码为 1

回帖(1)

hsdou月半

2025-3-17 18:05:55

在解决STM32 VSCode扩展编译失败的问题时,可以按照以下步骤进行排查和修复:




1. 检查工具链文件路径



  • 确认工具链文件存在:确保路径 C:/Users/Administrator/Desktop/HK_STM32_PLC_vscode/cmake/gcc-arm-none-eabi.cmake 中的文件确实存在。

  • 路径格式问题:Windows路径中的反斜杠应改为正斜杠(/)或用双引号包裹路径:
    -DCMAKE_TOOLCHAIN_FILE="C:/Users/.../gcc-arm-none-eabi.cmake"




2. 安装并配置ARM工具链



  • 安装 arm-none-eabi-gcc:从 ARM官网 下载并安装。

  • 添加到系统PATH:将工具链的 bin 目录(如 C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin)添加到环境变量。




3. 手动运行CMake命令


在终端中执行以下命令,观察详细错误信息:


F:/programs/STM32CubeCLT_1.16.0/CMake/bin/cmake.EXE 
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_TOOLCHAIN_FILE="C:/Users/.../gcc-arm-none-eabi.cmake"
-S "C:/Users/.../HK_STM32_PLC_vscode"
-B "C:/Users/.../build/Debug"
-G Ninja


  • 关键错误定位:如果提示找不到编译器(如 arm-none-eabi-gcc),检查工具链路径配置。




4. 检查工具链文件内容


打开 gcc-arm-none-eabi.cmake,确认以下配置:


# 示例配置
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_LINKER arm-none-eabi-ld)


  • 路径硬编码问题:如果工具链文件中指定了绝对路径(如 C:/gnuarm/bin/arm-none-eabi-gcc),需修改为实际安装路径。




5. 检查项目依赖和配置



  • STM32CubeMX生成的代码:确保项目基于CubeMX生成,且 CMakeLists.txt 包含必要的HAL库和启动文件。

  • 芯片型号匹配:确认工具链文件中的 -mcpu=cortex-mx-DSTM32xx 与实际芯片一致。




6. 清理并重新生成构建目录



  • 删除 build/Debug 目录,重新运行配置。

  • 使用VSCode命令 “Reload Window” 或重启IDE。




7. 权限问题



  • 将项目移动到非系统保护目录(如 D:/Projects/),避免因权限不足导致生成失败。




8. 更新工具和扩展



  • 升级STM32CubeCLT:从ST官网下载最新版本。

  • 更新VSCode扩展:如ST官方扩展或Cortex-Debug插件。




常见错误示例及解决



  • 错误:arm-none-eabi-gcc: not found

    • 解决方案:重新安装工具链并正确配置PATH。


  • 错误:CMake Error: The source directory ... does not appear to contain CMakeLists.txt

    • 解决方案:检查 -S 后的路径是否包含项目根目录的 CMakeLists.txt





通过以上步骤应能定位并解决问题。如果仍有错误,请提供 完整的CMake输出日志 或截图以进一步分析。

举报

更多回帖

发帖
×
20
完善资料,
赚取积分