Details |
Message |
Read-Only
Author Alistair Lowe
Posted 12-Oct-2012 11:49 GMT
Toolset None
|
 How to prevent Error: L6200E: Symbol multiply defined?
Alistair Lowe
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
|
|
Read-Only
Author Per Westermark
Posted 12-Oct-2012 12:24 GMT
Toolset None
|
 RE: How to prevent Error: L6200E: Symbol multiply defined?
Per Westermark
"With most compilers"? You seen any C compiler that does not
support the use of inclusion guards in header files?
You have given too little information, but you definitely seem to
do something wrong.
|
|
Read-Only
Author l kampot
Posted 12-Oct-2012 12:31 GMT
Toolset None
|
 RE: How to prevent Error: L6200E: Symbol multiply defined?
l kampot
quoter@ Would prevent double inclusion, however it doesn't appear
to work with Keil.
that does work on keil.
wothca probably got is function in two .c file with the same
name.
|
|
Read-Only
Author Andrew Neil
Posted 12-Oct-2012 12:44 GMT
Toolset None
|
 RE: function in two .c file with the same name
Andrew Neil
That would also do it.
And note that it's not just functions - anything defined at file
scope is global unless you specifically declare it as
static
|
|
Read-Only
Author Andrew Neil
Posted 12-Oct-2012 12:42 GMT
Toolset None
|
 This has (almost certainly) nothing to do with "double inclusion"!
Andrew Neil
"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: http://c-faq.com/decl/decldef.html
|
|
Read-Only
Author Alistair Lowe
Posted 12-Oct-2012 16:03 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Alistair Lowe
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
|
|
Read-Only
Author Hans-Bernhard Broeker
Posted 12-Oct-2012 20:43 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Hans-Bernhard Broeker
Sorry to rain on your parade, but this
I've just rewritten my code in C++ and now it's looking much
cleaner.
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.
|
|
Read-Only
Author Bob Dole
Posted 12-Oct-2012 23:19 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Bob Dole
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.
|
|
Read-Only
Author Alistair Lowe
Posted 14-Oct-2012 09:17 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Alistair Lowe
I'm quite aware of what definitions mean and there was never any
doubt in my mind as to the difference between this and a declaration,
however having never received the error 'L6200E: Symbol multiply
defined' before it wasn't immediately obvious (I'm used to symbol
errors being related to library linking).
Coding in C++ there's a natural line between definitions only
going in class header definitions and declarations in the
accompanying cpp, generally with slightly more obvious error messages
if you break from this. Likewise, I rarely find myself having to use
the keyword 'extern' in an OO environment and am a bit rusty as to
its use.
So what I meant by cleaned up with a C++ rewrite was that I simply
followed standard C++ coding practise and it naturally solved the
issue (after forum users generously highlighted the cause for me) and
gave me the OO code I was wanting at the same time.
And thanks Bob for not jumping to conclusions.
|
|
Read-Only
Author Dominic Fandrey
Posted 14-Oct-2012 11:02 GMT
Toolset None
|
 RE: No need for extern in C++
Dominic Fandrey
That's just because you rarely use globals in C++, the same
problem would have occurred in C++ if you had tried the same
thing.
Instead you hand around pointers and references. The advantage is
that pointers are just addresses, so declaring a class is sufficient,
you don't need to know any internals to be able to create a pointer
to it. References are just a different syntax for constant pointers
(not pointers to constants), so the same applies to them.
|
|
Read-Only
Author Hans-Bernhard Broeker
Posted 14-Oct-2012 13:11 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Hans-Bernhard Broeker
I'm quite aware of what definitions mean and there was never
any doubt in my mind as to the difference between this and a
declaration,
[...]
Coding in C++ there's a natural line between definitions only going
in class header definitions and declarations in the accompanying
cpp,
You've just proved yourself wrong in the space of two paragraphs.
You got the very difference that you claim to understand fully
exactly bass-ackwards in the second part of that quote.
So regardless whether I might have jumped to it or not, you've
just proved my conclusion was correct.
|
|
Read-Only
Author Alistair Lowe
Posted 14-Oct-2012 13:42 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Alistair Lowe
Potato Potato, it's called dyslexia, doesn't mean I don't know the
difference and rather, the fact that I've appropriately treated the
two separately proves the opposite, that's proof, transiently
interchanging two words proves nothing on the other-hand, though
thank you for pointing out the error so that it doesn't confuse other
readers.
|
|
Read-Only
Author Hans-Bernhard Broeker
Posted 14-Oct-2012 15:11 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Hans-Bernhard Broeker
doesn't mean I don't know the difference
I'm calling male bovine excrement on that one.
the fact that I've appropriately treated the two separately
proves the opposite,
And the fact your started this thread, asking the question you did
proves you wrong. If you actually knew which is which, there's just
no way the original error message you got from the linker could have
been anything but totally clear to you, so you wouldn't have had to
ask here to begin with.
And frankly, if you really have dyslexia at that level you're
laying claim to, I have to point out you've picked just about the
worst profession you possibly could have.
|
|
Read-Only
Author Alistair Lowe
Posted 14-Oct-2012 15:45 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Alistair Lowe
Reason for starting this thread: Error message was new (having
never mixed the two before in actuality, familiar only with the
notion of symbols in library linking).
Reason for resolution: Understood the problem at hand and resolved
(only possible with understanding) - that's called proof fyi.
Reason for profession: Spell-check, documentation and creative
license kind of renders dyslexia mute, thankfully dyslexia and
logical thinking aren't related, though, the logical reasoning that
dyslexia would some how prevent me from doing this profession leaves
me somewhat bemused.
Reason for your unprofessional/unfriendly attitude on dedicated
product support forums: I don't care, however, you're an annoyance
and a distraction so go away.
|
|
Read-Only
Author J Rakhomen
Posted 14-Oct-2012 18:17 GMT
Toolset None
|
 One of those annoyances best ignored
J Rakhomen
Reason for your unprofessional/unfriendly attitude on dedicated
product support forums: I don't care, however, you're an annoyance
and a distraction so go away.
Unfortunately he sticks around like a particularly bad smell. Must
be something relevant to his use of the term male bovine
excrement.
|
|
Read-Only
Author Bob Dole
Posted 15-Oct-2012 16:43 GMT
Toolset None
|
 RE: This has (almost certainly) nothing to do with "double inclusion"!
Bob Dole
This forum is filled with jerks. Just ignore them. Glad you were
able to resolve your issues!
|
|