2
\$\begingroup\$

I want to write my own implementation of SERCOM3_Handler. I put its definition in my main.c, try to compile it and get "multiple definition of SERCOM3_Handler" error. Why is this happening? The prototype of this function in the library headers is with the weak attribute.

\$\endgroup\$
  • 1
    \$\begingroup\$ It seems that someone else has already defined that function without the weak attribute. Doesn't the linker tell where that conflicting definition is? \$\endgroup\$ – Wouter van Ooijen Nov 11 '15 at 13:05
  • \$\begingroup\$ What uC are you using? SERCOM3_handler doesnt sound familiar to me. Are you sure that is the appropriate name for the ISR? What function of the uC are you trying to use? USART? \$\endgroup\$ – cventu Nov 11 '15 at 13:30
  • \$\begingroup\$ are you sure you haven't put the definition of the function in a header file somewhere (as opposed to a declaration)? An alternative possibility is that you are #including "main.c" somewhere? Finally as @Wouter hints at the SERCOM3_Handler is already defined somewhere else - perhaps in a library? Actually just read - "the prototype has weak attribute" - try changing your declaration in main.c to be 'strong' \$\endgroup\$ – Icy Nov 11 '15 at 14:39
  • \$\begingroup\$ I am using SAM D20 uC. In startup_samd20.c library file there is following line: void SERCOM3_Handler ( void ) attribute ((weak, alias("Dummy_Handler"))); \$\endgroup\$ – c_spk Nov 13 '15 at 5:21
  • \$\begingroup\$ In agreement with what others have said, I've had this happen when FreeRTOS defined a handler that I didn't think it was using. Just grep (or some other recursive in-file search tool) your project folder: grep -rin SERCOM3_Handler \$\endgroup\$ – ahogen Jan 27 '18 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.