xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

M1 arm-none-eabi-gcc & xmake compile stm32 project Unable to pass #4778

Closed cc-cao closed 8 months ago

cc-cao commented 8 months ago

Xmake 版本

2.8.7

操作系统版本和架构

macos sonoma 14.3.1

描述问题

I don't know what to do with it, or even why, and it compiles well on Windows 11 I am unable to link properly and it inexplicably generates some undefined ldflag -dead_strip

期待的结果

I hope it compiles properly

工程配置

`add_rules("mode.debug", "mode.release")

toolchain("arm-none-eabi") set_kind("standalone") set_sdkdir("$(projectdir)/../arm-gnu-toolchain") toolchain_end()

target("main") set_languages("c11") set_targetdir("build") set_filename("A2Plus.elf") set_toolchains("arm-none-eabi") set_kind("binary")

add_defines("USE_HAL_DRIVER", "STM32F103xE")
-- add_defines("DEBUG")

add_files(
    "drivers/STM32F1xx_HAL_Driver/Src/*.c",
    "middlewares/FreeRTOS/Source/*.c",
    "middlewares/FreeRTOS/Source/portable/MemMang/*.c",
    "middlewares/FreeRTOS/Source/portable/GCC/ARM_CM3/*.c",
    "middlewares/FreeRTOS/Source/CMSIS_RTOS_V2/*.c",
    "src/*.c",
    "src/utils/*.c",
    "src/thread/*.c",
    "src/bsp/*.c",
    "src/startup_stm32f103xe.s"
)

add_includedirs(
    "src/include",
    "src/bsp",
    "src/utils",
    "src/thread",
    "drivers/CMSIS/Include",
    "drivers/CMSIS/Device/ST/STM32F1xx/Include",
    "drivers/STM32F1xx_HAL_Driver/Inc/Legacy",
    "drivers/STM32F1xx_HAL_Driver/Inc",
    "middlewares/FreeRTOS/Source/include",
    "middlewares/FreeRTOS/Source/portable/GCC/ARM_CM3",
    "middlewares/FreeRTOS/Source/CMSIS_RTOS_V2"
)

add_cflags(
    "-mcpu=cortex-m3",
    "-mthumb",
    "-Og",
    "-Wall -fdata-sections -ffunction-sections",
    {force = true}
)

add_asflags(
    "-mcpu=cortex-m3",
    "-mthumb",
    "-Og",
    "-Wall -fdata-sections -ffunction-sections",
    "-x assembler-with-cpp",
    {force = true}
)

add_ldflags(
    "-mcpu=cortex-m3",
    "-mthumb",
    "-specs=nano.specs",
    "-specs=nosys.specs",
    "-T./src/STM32F103VETx_FLASH.ld",
    "-lc -lm -lnosys",
    "-Wl,--gc-sections",
    {force = true}
)

after_build(function(target, opt)
    local targetfile = target:targetfile()
    local toolchain_path = "$(projectdir)/../arm-gnu-toolchain"
    arm_objcopy = format("%s/bin/arm-none-eabi-objcopy", toolchain_path)
    arm_size = format("%s/bin/arm-none-eabi-size", toolchain_path)
    os.exec(arm_objcopy .. " -O ihex " .. targetfile .. " " .. string.gsub(targetfile, "elf", "hex"))
    os.exec(arm_objcopy .. " -O binary " .. targetfile .. " " .. string.gsub(targetfile, "elf", "bin"))
    os.exec(arm_size .. " -Ax " .. targetfile)
    os.exec(arm_size .. " -Bx " .. targetfile)
    os.exec(arm_size .. " -Bd " .. targetfile)
end)

`

附加信息和错误日志

error: /Users/cc/Downloads/arm-gnu-toolchain/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: Error: unable to disambiguate: -dead_strip (did you mean --dead_strip ?) collect2: error: ld returned 1 exit status

cc-cao commented 8 months ago
Snipaste
cc-cao commented 8 months ago

my arm-toolchain download url

waruqi commented 8 months ago

if you use cross toolchain, you should switch to cross platform.

xmake f -p cross or set_plat("cross")