Hi guys,
I'm receiving the Error: 'L6200E: Symbol multiply defined'.
I understand one workaround is to include externs, however this is unideal. With most compilers/linkers something such as:
#ifndef bla #define bla
// Content
#endif
Would prevent double inclusion, however it doesn't appear to work with Keil.
Any ideas on a similar solution?
Many thanks
"I understand one workaround is to include externs"
Pardon?
extern is not a "workaround"! It is the correct way to give one file access to symbols from another - ie, to symbols which are external to it!
"however this is unideal"
How so?
"With most compilers/linkers something such as ... Would prevent double inclusion"
So-called "include guards" like this have nothing to do with Linkers.
"it doesn't appear to work with Keil"
It does work with Keil! But, of course, if your problem is not multiple-inclusion, then it won't solve it!
Include Guards prevent multiple inclusion of the header in the same translation unit - but do nothing to prevent multiple definitions due to including the same header in multiple translation units!
The solutions is to not have definitions in your headers.
See: c-faq.com/.../decldef.html
Sorry about this guys,
I'm coming at this as a person who uses C++ primarily for any project large enough to be in multiple files, where naturally I'd know straight away if I'd defined something in my header and got into the bad habit of doing it without realising.
I've just rewritten my code in C++ and now it's looking much cleaner.
Cheers
Sorry to rain on your parade, but this
clearly indicates you haven't understood the problem. This has nothing to do with C vs. C++, so moving to C++ can only have brushed the problem under the carpet, or made it a nicer-looking problem --- but it rather certainly didn't solve anything.
Your code had a plain and simple coding mistake which the compiler did tell you about right there in the original error message: multiple definitions. Get out your textbooks and look up the distinction between definitions and declarations, and you'll understand what actually did go wrong.
While you may be correct, you are also making assumptions as to what he means by "cleaned up." It could be that when he rewrote his code, it caused him to review what it was written as and he addressed a number of these issues.
View all questions in Keil forum