This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to prevent Error: L6200E: Symbol multiply defined?

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

Parents
  • "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

Reply
  • "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

Children