Keil Logo

Error: L6200E: Symbol multiply defined

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Eliot Cuesta
Posted
20-Jul-2015 11:15 GMT
Toolset
None
New! Error: L6200E: Symbol multiply defined

I have a code with following files:

- Extern_file.h

int variable = 5;

void function (void);

- Extern_file.c

#include Extern_file.h

void function (void){ variable++; }

- main.c

#include Extern_file.h

int main(void){ function(); return 0; }

When link, I got the error:.\Objects\Blinky_LEDS.axf: Error: L6200E: Symbol variable multiply defined (by Extern_file.o and main.o).
Im working over a code made from component designer (stm32F105) and migrating to nrf51822. This is only a simplified example.
Why can't I link it?
If I use CoIDE I don't have this problem.
I have readed another link about this problem, but I can't solve it.
http://www.keil.com/forum/21633/

Thanks.

Read-Only
Author
Andrew Neil
Posted
20-Jul-2015 11:29 GMT
Toolset
None
New! RE: Why can't I link it?

Because, as the error message tells you, you have multiple definitions of the symbol 'variable'.

- Extern_file.h

int variable = 5;

That is almost certainly your problem!

That is a definition of the symbol 'variable'.

Therefore, every file which #includes Extern_file.h will contain a definition of the symbol 'variable'.

Therefore, if multiple (ie, more than one) files #include Extern_file.h, you will obviously have multiple definitions!!

http://c-faq.com/decl/decldef.html

Read-Only
Author
p pp
Posted
20-Jul-2015 11:32 GMT
Toolset
None
New! RE: Error: L6200E: Symbol multiply defined

Why can't I link it?

Because you have two compilation units each with the

int variable = 5;

You can only initialize the variable in one unit.

So, for example, put the

int variable = 5;

into main.c and change the header file to have just

int variable;

Advise that you read your C reference manual for definition, declaration and initialization.

Read-Only
Author
Andrew Neil
Posted
20-Jul-2015 11:37 GMT
Toolset
None
New! RE: change the header

Better, change the header file to have:

extern int variable;

"Advise that you read your C reference manual for definition, declaration and initialization"

Yes - that's the key!

Here's some 'C' reference/learning materials:
http://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/

Read-Only
Author
p pp
Posted
20-Jul-2015 11:53 GMT
Toolset
None
New! RE: change the header

Better, change the header file to have:...

Yes, if he's going to make changes, he should best do it properly.

(but, I'm not sure the extern there is actually a technical requirement in C)

Read-Only
Author
cham paroosh
Posted
20-Jul-2015 11:34 GMT
Toolset
None
New! RE: Error: L6200E: Symbol multiply defined

youve got an error in multiplying too bit numbers and its overflowing

Read-Only
Author
Andrew Neil
Posted
20-Jul-2015 11:42 GMT
Toolset
None
New! RE: youve got an error in multiplying

"youve got an error in multiplying too bit numbers and its overflowing"

No - that has nothing to do with it whatsoever!

That's not what the "multiply" in the error message means!

It's "multiply" as in "severally" or "frequently".

It's a really poor and unhelpful way to write it!

I do wish Keil would change that - you'd have though a company from Cambridge, England would do better!

Read-Only
Author
Eliot Cuesta
Posted
20-Jul-2015 12:17 GMT
Toolset
None
New! RE: youve got an error in multiplying

I got it!
If I don't initialize the variable on header file, I can build project on DevC++, but not with keil.
If I put: extern int variable
on Keil, I can build project.

I have to follow this metod because Im following the code of the company that programmed the chip, and I prefer to change the less code as possible.

Thank you!

Read-Only
Author
Andrew Neil
Posted
20-Jul-2015 15:31 GMT
Toolset
None
New! Declarations & definitions

If you don't initialise it, the compiler may still take it as a definition.

Some compilers will assume that duplicate definitions are intended to be the same thing, and will "merge" them. The trouble with this is that there is no way for the compiler to tell whether you did actually intend them to be the same thing, or different things.

If you put in the 'extern', then it can only ever be a declaraion - and it makes your intention explicitly clear.

Read-Only
Author
MAHDI DAMARCHILU
Posted
7-Aug-2018 11:15 GMT
Toolset
ARM
New! RE: Error: L6200E: Symbol multiply defined

CONVERT YOUR VARIABLE TO DEFINE
OR
STOP INIT VARIABLE IN FILE "???.h" and init your variable in "???.cpp" ( or "???.c" )

I solved my problem this way

fuck my english writing :)

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.