cancel
Showing results for 
Search instead for 
Did you mean: 

clion uses arm gcc to compile code generated from cubemx file error

chenmo
Associate II

I copied a cubemx ioc file successfully compiled by keil mdk to another empty folder and generated the file, but a link error was reported.

This is cmakelist:

#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.27)

# specify cross-compilers and tools
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_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(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

# project settings
project(CtrBoard-H7_Manipulator C CXX ASM)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

#Uncomment for hardware floating point
add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)

#Uncomment for software floating point
#add_compile_options(-mfloat-abi=soft)

add_compile_options(-mcpu=cortex-m7 -mthumb -mthumb-interwork)
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)

# uncomment to mitigate c++17 absolute addresses warnings
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")

# Enable assembler files preprocessing
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>assembler-with-cpp>)

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Maximum optimization for speed")
add_compile_options(-Ofast)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
message(STATUS "Maximum optimization for speed, debug info included")
add_compile_options(-Ofast -g)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
message(STATUS "Maximum optimization for size")
add_compile_options(-Os)
else ()
message(STATUS "Minimal optimization, debug info included")
add_compile_options(-Og -g)
endif ()

include_directories(Core/Inc Drivers/STM32H7xx_HAL_Driver/Inc Drivers/STM32H7xx_HAL_Driver/Inc/Legacy Middlewares/Third_Party/FreeRTOS/Source/include Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F Drivers/CMSIS/Device/ST/STM32H7xx/Include Drivers/CMSIS/Include Middlewares/ST/ARM/DSP/Inc)

add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32H723xx)

file(GLOB_RECURSE SOURCES "Library/*.*" "Core/*.*" "Middlewares/*.*" "Drivers/*.*")

set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32H723VGTX_FLASH.ld)

add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
add_link_options(-mcpu=cortex-m7 -mthumb -mthumb-interwork)
add_link_options(-T ${LINKER_SCRIPT})

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

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}")

CLion show error:

====================[ Build | CtrBoard-H7_Manipulator.elf | Debug ]=============
D:\Jetbrains\CLion\bin\cmake\win\x64\bin\cmake.exe --build C:\Users\19242\Desktop\Manipulator_clion\cmake-build-debug --target CtrBoard-H7_Manipulator.elf -- -j 6
CMake Deprecation Warning:
Support for "Extra Generators" like

CodeBlocks

is deprecated and will be removed from a future version of CMake. IDEs may
use the cmake-file-api(7) to view CMake-generated project build trees.


-- Minimal optimization, debug info included
-- Configuring done (0.2s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/19242/Desktop/Manipulator_clion/cmake-build-debug
[ 2%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/fdcan.c.obj
[ 4%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/freertos.c.obj
[ 6%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/gpio.c.obj
[ 9%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/main.c.obj
[ 11%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/octospi.c.obj
[ 13%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/stm32h7xx_hal_msp.c.obj
[ 16%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/stm32h7xx_hal_timebase_tim.c.obj
[ 18%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/stm32h7xx_it.c.obj
[ 20%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/syscalls.c.obj
[ 23%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/sysmem.c.obj
[ 25%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Src/system_stm32h7xx.c.obj
[ 27%] Building ASM object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Core/Startup/startup_stm32h723vgtx.s.obj
[ 30%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c.obj
[ 32%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c.obj
[ 34%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c.obj
[ 37%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c.obj
[ 39%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c.obj
[ 41%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fdcan.c.obj
[ 44%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c.obj
[ 46%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c.obj
[ 48%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c.obj
[ 51%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c.obj
[ 53%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c.obj
[ 55%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c.obj
[ 58%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c.obj
[ 60%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ospi.c.obj
[ 62%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c.obj
[ 65%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c.obj
[ 67%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c.obj
[ 69%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c.obj
[ 72%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c.obj
[ 74%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c.obj
[ 76%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c.obj
[ 79%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/croutine.c.obj
[ 81%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c.obj
[ 83%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/list.c.obj
[ 86%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c.obj
[ 88%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c.obj
[ 90%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/queue.c.obj
[ 93%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c.obj
[ 95%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/tasks.c.obj
[ 97%] Building C object CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/timers.c.obj
[100%] Linking C executable CtrBoard-H7_Manipulator.elf
d:/gcc-arm/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe:C:/Users/19242/Desktop/Manipulator_clion/STM32H723VGTX_FLASH.ld:91: non constant or forward reference address expression for section .ARM.extab
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\CtrBoard-H7_Manipulator.elf.dir\build.make:751: CtrBoard-H7_Manipulator.elf] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/CtrBoard-H7_Manipulator.elf.dir/rule] Error 2
mingw32-make: *** [Makefile:123: CtrBoard-H7_Manipulator.elf] Error 2

i can't understand why this is error:

d:/gcc-arm/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe:C:/Users/19242/Desktop/Manipulator_clion/STM32H723VGTX_FLASH.ld:91: non constant or forward reference address expression for section .ARM.extab
collect2.exe: error: ld returned 1 exit status

chenmo_0-1711184829483.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Remove "(READONLY)" in line 93 and everywhere below it.

.ARM.extab (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */

 Or update your ARM toolchain to GCC 11 or newer as the comment says,

 

View solution in original post

4 REPLIES 4
Pavel A.
Evangelist III

This is linker (ld) error, it does not like something in the .ld file:

C:/Users/19242/Desktop/Manipulator_clion/STM32H723VGTX_FLASH.ld line 91

But you don't show us this file ((

 

Because this is generated by cubemx itself, I don't think there are any major issues when I look at it

chenmo_0-1711202034731.png

/*
******************************************************************************
**
** File : LinkerScript.ld
**
** Author : STM32CubeIDE
**
** Abstract : Linker script for STM32H7 series
** 1024Kbytes FLASH and 560Kbytes RAM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : STMicroelectronics STM32
**
** Distribution: The file is distributed as is, without any warranty
** of any kind.
**
*****************************************************************************
** @attention
**
** Copyright (c) 2024 STMicroelectronics.
** All rights reserved.
**
** This software is licensed under terms that can be found in the LICENSE file
** in the root directory of this software component.
** If no LICENSE file comes with this software, it is provided AS-IS.
**
****************************************************************************
*/

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x800; /* required amount of heap */
_Min_Stack_Size = 0x1200; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 320K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 32K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 16K
}

/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH

/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)

KEEP (*(.init))
KEEP (*(.fini))

. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH

/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH

.ARM.extab (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} >FLASH
.ARM (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH

.preinit_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH

.init_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH

.fini_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH

/* used by the startup to initialize data */
_sidata = LOADADDR(.data);

/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.RamFunc) /* .RamFunc sections */
*(.RamFunc*) /* .RamFunc* sections */

. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM_D1 AT> FLASH

/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)

. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM_D1

/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM_D1

/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}

.ARM.attributes 0 : { *(.ARM.attributes) }
}
Pavel A.
Evangelist III

Remove "(READONLY)" in line 93 and everywhere below it.

.ARM.extab (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */

 Or update your ARM toolchain to GCC 11 or newer as the comment says,

 

thank you!!!!

it works!