cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple definition error after STM32CubeIDE 1.9.0 update

Rodolfo_Rodrigues
Associate

I get a multiple definition error for every variable declared inside a .h file after updating from CubeIDe 1.8.0 to 1.9.0. The previous CubeMX version was 6.3.0 and now it is 6.5.0. Before updating there would be no errors while building the code. The .h file has the header guards generated by the IDE. Is there any way to fix this?

21 REPLIES 21
LFerr.7
Associate II

you are the best

"the better solution is to declare the variables in the header as "extern" and define them in one source file. Heres the link to the GNU GCC 10 source:"

At this point i've a problem.

In a work space, i've 2 project, one with a STM32L562 target and another with a STM32G070. The code have the same structure for the 2 projects.

I always use "extern" to define global variable and with the last version of stm32cubeide, it's working wel for the L562 target but i've a problem with the g070 device with the folowing error(s). What's wrong?

"arm-none-eabi-gcc "../Core/Src/stm32g0xx_it.c" -mcpu=cortex-m0plus -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32G070xx -c -I../Core/Inc -I../Drivers/STM32G0xx_HAL_Driver/Inc -I../Drivers/STM32G0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32G0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/stm32g0xx_it.d" -MT"Core/Src/stm32g0xx_it.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/stm32g0xx_it.o"

../Core/Src/stm32g0xx_it.c:60:12: warning: 'status' initialized and declared 'extern'

  60 | extern int status = 0;

     |           ^~~~~~

arm-none-eabi-gcc -o "G070CBT6.elf" @"objects.list"  -mcpu=cortex-m0plus -T"C:\Users\francois\Projets\BobineuseV1.0\200-Firmware\G070CBT6\STM32G070CBTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="G070CBT6.map" -Wl,--gc-sections -static --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -Wl,--end-group

c:\st\stm32cubeide_1.6.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: ./Core/Src/stm32g0xx_it.o:C:/Users/francois/Projets/BobineuseV1.0/200-Firmware/G070CBT6/Debug/../Core/Src/stm32g0xx_it.c:60: multiple definition of `status'; ./Core/Src/main.o:C:/Users/francois/Projets/BobineuseV1.0/200-Firmware/G070CBT6/Debug/../Core/Src/main.c:155: first defined here

collect2.exe: error: ld returned 1 exit status

make: *** [makefile:64: G070CBT6.elf] Error 1

"make -j4 all" terminated with exit code 2. Build might be incomplete."

0693W00000QMsN2QAL.png

Hi there,

i guess you have "extern int status = 0;" in the header file? If thats the case you should not initialized but declare the variable in the header file. Initializiation should be done in the according source file. eg.,

in the header file control.h:

extern int status;

and in the source file control.c

int status = 0;

if you then include the header file in a different source file you can use the global variable status there as well. I hope i could help, if not dont hessitate to come back. As a side note, if you declare a global variable with a scope beyond one source file, it can be a great help to name the variable in a way to indicate where the variable is from, in my case control_status would be better then just status, therefore i would know that the variable control_status is inside the control source file. Makes analyzing your code way easier, espacially if its not yourself.

DFran.10
Associate

Solved!

The problem was solved with upgrading to the last version of the HAL firmware package.

ETezc.1
Associate II

Thankns! It realy works.

Thankns! It realy works.

Thankns! It realy works.

mute �?р, 3 авг. 2022 г. в 19:36, ST Community :

Thanks a lot. The solution specified by you open project properties -> settings, under MCU GCC Compiler select Miscellaneous. Click add flag -fcommon is work for me. I had this issue when STM32CubeIDE is updated with STM32CUbeMX 6.6.1 from version 6.1.0.

Thank you very much for helping me fix the problem.