DSPRelated.com
Forums

symbols are defined multiple times??

Started by pavan kumar March 22, 2005

Hi Bhooshan and all,

Im having a Vc++-project which contains several C files. My
task is to convert these exisiting code to run on a TI C62x. After
having done the necessary modi-fications I have problems with the TI
Code Composer v3 linker.
When I compile the project,I get the following linking error:

[Linking...] "C:\CCStudioEval\C6000\cgtools\bin\cl6x" -@"Debug.lkf"
<Linking>
>> error: symbol _errortext is defined multiple times:

Likewise im getting some 450 symbol referencing errors.I don`t
understand why the symbols are defined multiple times
I would appreciate any hints/ideas how to fix this problem.
Thanks in advance
Pavan



Hi Pavan

This problem occurs when some header files contain declaration for
variables and these header files are included in several c files.

So I think u should remove such declarations from header files and
explicitly declare variables in one c file and as extern in remaining
files where they r used.
This is the way I handled this problem
Others can tell if there is some other way out.

Regards

Abhishek -----Original Message-----
From: pavan kumar [mailto:]
Sent: Tuesday, March 22, 2005 1:52 PM
To:
Subject: [c6x] symbols are defined multiple times??
Hi Bhooshan and all,

Im having a Vc++-project which contains several C files. My
task is to convert these exisiting code to run on a TI C62x. After
having done the necessary modi-fications I have problems with the TI
Code Composer v3 linker.
When I compile the project,I get the following linking error:

[Linking...] "C:\CCStudioEval\C6000\cgtools\bin\cl6x" -@"Debug.lkf"
<Linking>
>> error: symbol _errortext is defined multiple times:

Likewise im getting some 450 symbol referencing errors.I don`t
understand why the symbols are defined multiple times
I would appreciate any hints/ideas how to fix this problem.
Thanks in advance
Pavan


Pavan--
Just a comment, It's always better to address the mail to the group
rather than to an individual.

Anyways, this issue was very crisply answered by Jeff Brower in late a
2003 thread started by Raj under the name "Conditional Compilation".
It might be quite enlightening to go through the entire thread for a
thorough understanding about sharing data cross multiple files. I
quote from Jeff's mail here:

#ifndef _GLOBALS

#define DECLSPEC

#else

#define DECLSPEC extern

#endif DECLSPEC int a;
DECLSPEC int b;
.
.
.

then pick only *one* .c file and define _GLOBALS prior to including define.h,
for
example main.c:

#define _GLOBALS
#include define.h
#undef _GLOBALs

The idea is that *one* time the variables are declared (instantiated)
and use up mem space. All other times they are referenced as extern.
--Bhooshan
On Tue, 22 Mar 2005 08:21:47 +0000 (GMT), pavan kumar
<> wrote:
>
>
> Hi Bhooshan and all,
>
> Im having a Vc++-project which contains several C files. My
> task is to convert these exisiting code to run on a TI C62x. After
> having done the necessary modi-fications I have problems with the TI
> Code Composer v3 linker.
> When I compile the project,I get the following linking error:
>
> [Linking...] "C:\CCStudioEval\C6000\cgtools\bin\cl6x" -@"Debug.lkf"
> <Linking>
> >> error: symbol _errortext is defined multiple times:
>
> Likewise im getting some 450 symbol referencing errors.I don`t
> understand why the symbols are defined multiple times
> I would appreciate any hints/ideas how to fix this problem.
> Thanks in advance
> Pavan >
>


--
-------------------------------
"I've missed more than 9000 shots in my career.
I've lost almost 300 games. 26 times I've been trusted to take the
game winning shot and missed.
I've failed over and over again in my life.
And that is why I succeed."
-- Michael Jordan
--------------------------------




Hello,

You have correctly analysed the problem, but your suggested solution is very dangerous. It leads to symbols being separately declared in different .c files, so a change in one is not reflected in the others - a major source of potential bugs.

The ideal way is for all global symbols used in more than one .c file to be declared in a .h file, using the keyword extern. This file can then be included in all .c files which need access to the variables.

To get a single declaration in place, there are two possible techniques. One is to repeat the definitions - without the extern keyword - in one .c file only. This .c file can also have any initialisations required. As long as the .h file is also included in this .c file, the compiler can check for consistency of the two sets of definitions.

The second - a cheap shortcut - is to include the .h file in only one .c file (the same one which has any initialisations) - in the form
#define extern
#include "vars.h"
#undef extern

Roger Kingsley

> Message: 4
> Date: Tue, 22 Mar 2005 19:53:49 +0530
> From: "Abhishek Dixit" <>
> Subject: RE: symbols are defined multiple times?? > Hi Pavan
>
> This problem occurs when some header files contain declaration for
> variables and these header files are included in several c files.
>
> So I think u should remove such declarations from header files and
> explicitly declare variables in one c file and as extern in remaining
> files where they r used.
> This is the way I handled this problem
> Others can tell if there is some other way out.
>
> Regards
>
> Abhishek > -----Original Message-----
> From: pavan kumar [mailto:]
> Sent: Tuesday, March 22, 2005 1:52 PM
> To:
> Subject: [c6x] symbols are defined multiple times?? >
> Hi Bhooshan and all,
>
> Im having a Vc++-project which contains several C files. My
> task is to convert these exisiting code to run on a TI C62x. After
> having done the necessary modi-fications I have problems with the TI
> Code Composer v3 linker.
> When I compile the project,I get the following linking error:
>
> [Linking...] "C:\CCStudioEval\C6000\cgtools\bin\cl6x" -@"Debug.lkf"
> <Linking>
> >> error: symbol _errortext is defined multiple times:
>
> Likewise im getting some 450 symbol referencing errors.I don`t
> understand why the symbols are defined multiple times
> I would appreciate any hints/ideas how to fix this problem.
> Thanks in advance
> Pavan >



Roger-

> You have correctly analysed the problem, but your suggested solution
> is very dangerous. It leads to symbols being separately declared in
> different .c files, so a change in one is not reflected in the
> others - a major source of potential bugs.
>
> The ideal way is for all global symbols used in more than one .c file
> to be declared in a .h file, using the keyword extern. This file can
> then be included in all .c files which need access to the variables.
>
> To get a single declaration in place, there are two possible techniques.
> One is to repeat the definitions - without the extern keyword - in one
> .c file only. This .c file can also have any initialisations required.
> As long as the .h file is also included in this .c file, the compiler
> can check for consistency of the two sets of definitions.

This is the most dangerous thing in all of coding, in any language: 2 copies of
something in 2 different places that have to be kept in sync.

"Repeating" source code is a technique only used in a situation where one person is
the code king/queen and guards his/her empire and no others shall ever enter.

-Jeff > The second - a cheap shortcut - is to include the .h file in only one .c file (the same one which has any initialisations) - in the form
> #define extern
> #include "vars.h"
> #undef extern
>
> Roger Kingsley
>
> > Message: 4
> > Date: Tue, 22 Mar 2005 19:53:49 +0530
> > From: "Abhishek Dixit" <>
> > Subject: RE: symbols are defined multiple times??
> >
> >
> > Hi Pavan
> >
> > This problem occurs when some header files contain declaration for
> > variables and these header files are included in several c files.
> >
> > So I think u should remove such declarations from header files and
> > explicitly declare variables in one c file and as extern in remaining
> > files where they r used.
> > This is the way I handled this problem
> > Others can tell if there is some other way out.
> >
> > Regards
> >
> > Abhishek
> >
> >
> > -----Original Message-----
> > From: pavan kumar [mailto:]
> > Sent: Tuesday, March 22, 2005 1:52 PM
> > To:
> > Subject: [c6x] symbols are defined multiple times??
> >
> >
> >
> > Hi Bhooshan and all,
> >
> > Im having a Vc++-project which contains several C files. My
> > task is to convert these exisiting code to run on a TI C62x. After
> > having done the necessary modi-fications I have problems with the TI
> > Code Composer v3 linker.
> > When I compile the project,I get the following linking error:
> >
> > [Linking...] "C:\CCStudioEval\C6000\cgtools\bin\cl6x" -@"Debug.lkf"
> > <Linking>
> > >> error: symbol _errortext is defined multiple times:
> >
> > Likewise im getting some 450 symbol referencing errors.I don`t
> > understand why the symbols are defined multiple times
> > I would appreciate any hints/ideas how to fix this problem.
> > Thanks in advance
> > Pavan
> >
> >
> >



Roger-

> You have correctly analysed the problem, but your suggested solution
> is very dangerous. It leads to symbols being separately declared in
> different .c files, so a change in one is not reflected in the
> others - a major source of potential bugs.
>
> The ideal way is for all global symbols used in more than one .c file
> to be declared in a .h file, using the keyword extern. This file can
> then be included in all .c files which need access to the variables.
>
> To get a single declaration in place, there are two possible techniques.
> One is to repeat the definitions - without the extern keyword - in one
> .c file only. This .c file can also have any initialisations required.
> As long as the .h file is also included in this .c file, the compiler
> can check for consistency of the two sets of definitions.

This is the most dangerous thing in all of coding, in any language: 2 copies of
something in 2 different places that have to be kept in sync.

"Repeating" source code is a technique only used in a situation where one person is
the code king/queen and guards his/her empire and no others shall ever enter.

-Jeff > The second - a cheap shortcut - is to include the .h file in only one .c file (the same one which has any initialisations) - in the form
> #define extern
> #include "vars.h"
> #undef extern
>
> Roger Kingsley
>
> > Message: 4
> > Date: Tue, 22 Mar 2005 19:53:49 +0530
> > From: "Abhishek Dixit" <>
> > Subject: RE: symbols are defined multiple times??
> >
> >
> > Hi Pavan
> >
> > This problem occurs when some header files contain declaration for
> > variables and these header files are included in several c files.
> >
> > So I think u should remove such declarations from header files and
> > explicitly declare variables in one c file and as extern in remaining
> > files where they r used.
> > This is the way I handled this problem
> > Others can tell if there is some other way out.
> >
> > Regards
> >
> > Abhishek
> >
> >
> > -----Original Message-----
> > From: pavan kumar [mailto:]
> > Sent: Tuesday, March 22, 2005 1:52 PM
> > To:
> > Subject: [c6x] symbols are defined multiple times??
> >
> >
> >
> > Hi Bhooshan and all,
> >
> > Im having a Vc++-project which contains several C files. My
> > task is to convert these exisiting code to run on a TI C62x. After
> > having done the necessary modi-fications I have problems with the TI
> > Code Composer v3 linker.
> > When I compile the project,I get the following linking error:
> >
> > [Linking...] "C:\CCStudioEval\C6000\cgtools\bin\cl6x" -@"Debug.lkf"
> > <Linking>
> > >> error: symbol _errortext is defined multiple times:
> >
> > Likewise im getting some 450 symbol referencing errors.I don`t
> > understand why the symbols are defined multiple times
> > I would appreciate any hints/ideas how to fix this problem.
> > Thanks in advance
> > Pavan
> >
> >
> >



> -----Original Message-----
> From: Jeff Brower [mailto:]
> Sent: Wednesday, March 23, 2005 4:37 PM
> To: Roger Kingsley
> Cc: ; ;
> Subject: Re: [c6x] symbols are defined multiple times??
>
Jeff,

> This is the most dangerous thing in all of coding, in any language:
2
> copies of
> something in 2 different places that have to be kept in sync.

I think you have missed my point. The original idea posted had this
defect (replace N for 2), which is why I posted.
But in C - if the two copies are contained in a single file - the extern
tentative definition and the externless declaration appearing in the
same .c file, then the compiler will give an error if one is changed
without the other. Keeping two things in step is easy if the compiler
checks for you - disastrous if it doesn't.

Actually, I prefer the second solution, but many purists don't like it.

In any case, in C, for an initialised variable, you have no choice but
to have two copies, as the initialiser can occur in only one file,
unless you are going to go in for a very complex set of #defines and
#ifdefs. But, as I said above, the 2 copy solution is not dangerous
(unless you omit to include the .h file in the declaring .c file...)

Roger Kingsley



> Date: Wed, 23 Mar 2005 17:49:29 +0200
> From: "Roger Kingsley" <>
>
> Actually, I prefer the second solution, but many purists don't like it.

Hi Roger,

You probably wanted to say "none of the purists like it" or "all the purists
don't like it", they are "purists" after all. :)

> #define extern
> #include "vars.h"
> #undef extern

What if instead of killing/reviving the keyword, the inter-file globals
were put into a separate C source file and whenever needed an include
file with extern modifiers is #include-ed? Essentially the same, but
saved two lines of extra code. :)

Andrew