STM32 CubeMX에서 소스코드와 헤더파일을 추가하여 컴파일하다보면 아래와 같은 multiple definition of ... 오류가 빈번하게 나타난다. 특별히 문제가 될 만한 것이 없어 보이는데 자꾸 에러를 띄어서 여기저기 찾아보았다.
/opt/st/stm32cubeide_1.11.2/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.linux64_1.0.100.202210260954/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: ./Core/Src/usart.o:/home/swift/workspace/STM32CubeIDE/dev/STM32F4_FC_DEV/Debug/../Core/Inc/usart.h:41: multiple definition of `state'; ./Core/Src/main.o:/home/swift/workspace/STM32CubeIDE/dev/STM32F4_FC_DEV/Debug/../Core/Inc/usart.h:41: first defined here
/opt/st/stm32cubeide_1.11.2/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.linux64_1.0.100.202210260954/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: ./Core/Src/usart.o:/home/swift/workspace/STM32CubeIDE/dev/STM32F4_FC_DEV/Debug/../Core/Inc/usart.h:46: multiple definition of `is_full'; ./Core/Src/main.o:/home/swift/workspace/STM32CubeIDE/dev/STM32F4_FC_DEV/Debug/../Core/Inc/usart.h:46: first defined here
/opt/st/stm32cubeide_1.11.2/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.linux64_1.0.100.202210260954/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: ./Core/Src/usart.o:/home/swift/workspace/STM32CubeIDE/dev/STM32F4_FC_DEV/Debug/../Core/Inc/usart.h:51: multiple definition of `increase'; ./Core/Src/main.o:/home/swift/workspace/STM32CubeIDE/dev/STM32F4_FC_DEV/Debug/../Core/Inc/usart.h:51: first defined here
collect2: error: ld returned 1 exit status
make: *** [makefile:64: STM32F4_FC_DEV.elf] Error 1
"make -j8 all" terminated with exit code 2. Build might be incomplete.
구글링을 해보니 같은 문제를 호소하는 사람이 있었고, 이전버전에는 그냥 Warning으로 처리했는데 버전이 바뀌면서부터 모두 에러로 레포트를 하면서 문제가 되었다.
이 문제는 같은 변수가 여러군데 define이 되어 있다고 띄우는 에러인데 소스코드를 수정할 수 있으면 수정하면 되고, 특별히 문제될 것이 없는데 에러를 띄운다면 아래와 같은 방법으로 해결할 수 있다.
Project → Properties → C/C++ Build → Setting → Tool Settings →MCU GCC Compiler → Miscellaneous 에서 아래 플래그를 추가하면 된다.
-fcommon
플래그 입력후 컴파일해보면 문제없이 컴파일된다.
728x90
댓글