Skip to main content
Robert Poor
Associate III
July 10, 2022
Question

multiple definition of `SystemCoreClock' (system_stm32g4xx.c included twice)

  • July 10, 2022
  • 4 replies
  • 7537 views

I thought this was a manifestation of the previously reported bug Multiple definition error after STM32CubeIDE 1.9.0 update, but adding -fcommon to my compiler flags didn't fix it.

The error message is:

  • multiple definition of `SystemCoreClock'
  • multiple definition of `AHBPrescTable'

The root problem appears that two copies of system_stm32g4xx.c are being included in the build:

  • Core/Src/system_stm32g4xx.c
  • Drivers/CMSIS/Device/ST/STM32G4xx/Source/Templates/system_stm32g4xx.c

Here's an example of the full error message:

c:\st\stm32cubeide_1.9.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: ./Drivers/CMSIS/Device/ST/STM32G4xx/Source/Templates/system_stm32g4xx.o:C:/Users/r/Projects/mulib-examples/test_stdbsp/nucleo_g431rb/Debug/../Drivers/CMSIS/Device/ST/STM32G4xx/Source/Templates/system_stm32g4xx.c:152: multiple definition of `SystemCoreClock'; ./Core/Src/system_stm32g4xx.o:C:/Users/r/Projects/mulib-examples/test_stdbsp/nucleo_g431rb/Debug/../Core/Src/system_stm32g4xx.c:152: first defined here

The questions:

Is this a known issue, and if so, what's a suitable workaround or proper fix?

A newcomer, what's the best way to capture the relevant environmental info in STM32CubeIDE?

Environment:

STM32CubeIDE

Version: 1.10.0

Build: 12671_20220627_1643 (UTC)

C/C++ Development Platform

Version: 10.6.2.202205170638

Build id: 20220517-0638

Eclipse Platform

Version: 4.23.0.v20220308-0722

Build id: I20220308-0310

STM32CubeIDE - C/C++ Embedded Development Tools for MCU

Version: 2.0.100.202110131350

Windows 11 Pro v 22H2

This topic has been closed for replies.

4 replies

Robert Poor
Associate III
July 10, 2022

Update:

For the nonce, my workaround is to simply exclude Core/Src/system_stm32g4xx.c from the build (so it uses the file from CMSIS instead). It compiled and linked without error.

Khouloud OTHMAN
Associate
July 12, 2022

Hello @Robert Poor​ ,

First let me thank you for having reported :smiling_face_with_smiling_eyes:

In fact I wasn't able to reproduce any building issue from my side when starting a project based on STM32G431RBTx MCU and using the latest version of STM32CubeMX / STM32CubeIDE: the build has finished without any errors.

Could you please add more details about how did you proceed or attach your .ioc file to be able to further investigate from my side.

Your feedback will be very helpful to track the root cause of the issue.

Khouloud.

CJans.1
Associate III
October 9, 2022

I have same kind of problem: multiple defined symbols:

SystemCoreClock

SystemD2Clock

D1CorePrescTable

SystemInit

SystemCoreClockUpdate

22:17:38 **** Incremental Build of configuration Debug for project SmartCam1 ****
make -j8 all 
arm-none-eabi-g++ -o "SmartCam1.elf" @"objects.list" -mcpu=cortex-m7 -T"D:\Dropbox (Mechamania)\Exoleap\sub_projects\SmartCam\software\SmartCam1\STM32H743VITX_FLASH.ld" --specs=nosys.specs -Wl,-Map="SmartCam1.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
c:\st\stm32cubeide_1.10.1\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: ./Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.o:D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c:148: multiple definition of `SystemCoreClock'; ./Core/Src/system_stm32h7xx.o:D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Core/Src/system_stm32h7xx.c:148: first defined here
c:\st\stm32cubeide_1.10.1\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: ./Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.o:D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c:149: multiple definition of `SystemD2Clock'; ./Core/Src/system_stm32h7xx.o:D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Core/Src/system_stm32h7xx.c:149: first defined here
c:\st\stm32cubeide_1.10.1\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: ./Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.o:D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c:150: multiple definition of `D1CorePrescTable'; ./Core/Src/system_stm32h7xx.o:D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Core/Src/system_stm32h7xx.c:150: first defined here
c:\st\stm32cubeide_1.10.1\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: ./Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.o: in function `SystemInit':
D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c:176: multiple definition of `SystemInit'; ./Core/Src/system_stm32h7xx.o:D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Core/Src/system_stm32h7xx.c:176: first defined here
c:\st\stm32cubeide_1.10.1\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: ./Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.o: in function `SystemCoreClockUpdate':
D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c:341: multiple definition of `SystemCoreClockUpdate'; ./Core/Src/system_stm32h7xx.o:D:/Dropbox (Mechamania)/Exoleap/sub_projects/SmartCam/software/SmartCam1/Debug/../Core/Src/system_stm32h7xx.c:341: first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:84: SmartCam1.elf] Error 1
"make -j8 all" terminated with exit code 2. Build might be incomplete.
 
22:17:39 Build Failed. 8 errors, 0 warnings. (took 1s.357ms)

I zipped and attacjed my project folder.

Pavel A.
Super User
October 9, 2022

@CJans.1​ Files in Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates should not be included in build.

Is your makefile generated by CubeMX or CubeIDE? If not, please fix the makefile or CubeIDE project.

Robert Poor
Associate III
October 9, 2022

Regarding the OP, note that I used CubeIDE, and I didn't specifically ask for two copies of system_stm32g4xx.c, but that's what CubeIDE generated. I had to manually exlude of of the two from the project to get it to compile.

This seems like a bug.

CJans.1
Associate III
October 9, 2022

How should I remove it? Just delete it from the project browser? I do not want to delete anything that I should not delete.

Pavel A.
Super User
October 10, 2022
  1. Exclude all these duplicate files in /Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/ from build.
  2. If this helps, you can delete the directory /Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/ if it is copied into your project directory, then refresh the project in eclipse.
  3. Consider instead of copying the ST library files into your project directory to create references to the library location (share the ST library among many projects).

GMene.785
Associate II
November 25, 2022

Thanks! Had the same issue, deleting manually works fine, but when regenerating code I need to delete it again :downcast_face_with_sweat: .