I declared a mailbox 'DMAmbx' in a header file called definitions.h, initialized it in the main function and used it to send messages through an interrupt service routine in a different file (dma.cpp). Both main.cpp and dma.cpp have the header file included. The header file has include guards.
The program compiled each file with no errors. However, I received the error L6200E during linking. The error was that the symbol DMAmbx was multiply defined by dma.o and main.o.
All examples on Keil using mailboxes have all functions that access them in the same file. Is this a rule? If not, how is it possible to access the mailbox from multiple files?
Thank you for the quick reply, Dan! That solved the issue.
You have to realize that include guards are intended to make sure that if header file A includes header file C and header file B includes header file C, then the contents of header file C will only be processed once.
But include guards are reset each time the compiler switches to compiling the next C/C++ file.
So include guards will never help when you get to the linker - it will only help when creating a hierarchical set of header files where the individual header files draws in other header files.
I see. That makes sense. Thank you, Per!