0

我正在尝试将嵌入式 gcc arm- 项目转换为使用 ARMClang 而不是 GCC。我的重点是使用 CMake 自动生成生成文件的任务,但我不明白为什么我不能强制执行链接器标志,并且在构建过程中总是出现以下错误

[ 96%] 构建 ASM 对象 CMakeFiles/CLION-f103-armclang.elf.dir/startup/startup_stm32f103xb.o 致命错误:A9912E:未选择 --cpu

我的 CMakeLists.txt 文件的内容如下

#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)

cmake_minimum_required(VERSION 3.15)

# specify cross compilers and tools
#SET(CMAKE_C_COMPILER_ID ARMClang)
#SET(CMAKE_CXX_COMPILER_ID ARMClang)
#SET(CMAKE_ASM_COMPILER_ID ARMClang)
SET(TARGET "arm-arm-none-eabi")
SET(CMAKE_C_COMPILER_TARGET ${TARGET})
SET(CMAKE_CXX_COMPILER_TARGET ${TARGET})
SET(CMAKE_ASM_COMPILER_TARGET ${TARGET})
SET(CMAKE_SYSTEM_PROCESSOR Cortex-M3)


SET(CMAKE_C_COMPILER_ID ARMClang)
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_C_COMPILER armclang)
SET(CMAKE_CXX_COMPILER_WORKS 1)
SET(CMAKE_CXX_COMPILER armclang)
SET(CMAKE_ASM_COMPILER_WORKS 1)
set(CMAKE_ASM_COMPILER armasm)
#set(CMAKE_AR arm-none-eabi-ar)
#set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
#set(CMAKE_OBJDUMP arm-none-eabi-objdump)
#set(SIZE arm-none-eabi-size)

SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F103RBTx_FLASH.ld)

#Uncomment for hardware floating point
#SET(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16")
#add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)

#Uncomment for software floating point
#SET(FPU_FLAGS "-mfloat-abi=soft")

SET(COMMON_FLAGS
    "${FPU_FLAGS} -mthumb -ffunction-sections -fdata-sections \
    -g -fno-common -fmessage-length=0")


SET(WARNING_FLAGS "-Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes \
                   -Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path \
                   -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command \
                   -Wno-documentation -Wno-license-management -Wno-parentheses-equality")
SET(COMPILER_OPT_FLAGS "-flto -Ofast -ffunction-sections ")
SET(TCPU_FLAGS "--target=arm-arm-none-eabi -mcpu=cortex-m3")
SET(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} ${WARNING_FLAGS} ${COMPILER_OPT_FLAGS} ${TCPU_FLAGS} -std=c++11 -fno-rtti  -funsigned-char -fshort-enums -fshort-wchar -gdwarf-3")
SET(CMAKE_C_FLAGS_INIT "${COMMON_FLAGS} ${WARNING_FLAGS} ${COMPILER_OPT_FLAGS} ${TCPU_FLAGS} -std=gnu99 -fno-rtti -flto -funsigned-char -fshort-enums -fshort-wchar -gdwarf-3")
#SET(CMAKE_EXE_LINKER_FLAGS_INIT "--info sizes --info totals --info unused --info veneers -g --lto -Wl,-gc-sections,--print-memory-usage -T ${LINKER_SCRIPT}")
SET(CMAKE_EXE_LINKER_FLAGS_INIT "--info sizes --info totals --cpu Cortex-M3\
     --info unused --info veneers -g\
     --lto -gc-sections,--print-memory-usage\
     -T ${LINKER_SCRIPT}" CACHE INTERNAL "" FORCE)
PROJECT(CLION-f103-armclang C CXX ASM)
set(CMAKE_CXX_STANDARD 11)

#add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
add_definitions(-D__weak=__attribute__\(\(weak\)\) -D__packed=__attribute__\(\(__packed__\)\) -DUSE_HAL_DRIVER -DSTM32F103xB)

file(GLOB_RECURSE SOURCES "startup/*.*" "Drivers/*.*" "Core/*.*")

include_directories(Core/Inc Drivers/STM32F1xx_HAL_Driver/Inc Drivers/STM32F1xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32F1xx/Include Drivers/CMSIS/Include)

add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_INIT} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map"  CACHE INTERNAL "" FORCE)

set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)

add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
        COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
        COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
        COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")

首先,要使脚本正确构建和链接,CMakeLists.txt 文件需要进行哪些更改!?其次,如何使链接器输出标志看起来尽可能地遵循。

--cpu Cortex-M3 -g
-I.\RTE\_stm32f103rbt6-LCD-CubeMX
-IC:\Users\U1\AppData\Local\Arm\Packs\ARM\CMSIS\5.5.1\CMSIS\Core\Include
-IC:\Users\U1\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.3.0\Device\Include
--pd "__UVISION_VERSION SETA 528"
--pd "_RTE_ SETA 1"
--pd "STM32F10X_MD SETA 1"
--list *.lst
--xref -o stm32f103rbt6-LCD-CubeMX\*.o
--depend stm32f103rbt6-LCD-CubeMX\*.d

非常感谢任何帮助

4

0 回答 0