DSPRelated.com
Forums

-pm option triggers "defined multiple times" link errors

Started by ".dorian" January 4, 2008
Hi guys,

first of all, before some people get nerved: yes, I used the search function
and I also a read the threads concerning this topic =)
---

When I turn on the -pm option, I get 76 link errors la:

>> error: symbol _X is defined multiple times:
Y.obj and common.obj

X is always a function name, and Y is a source file name.

The common.obj(includes most of the other .h files) is always mentioned in
the
error messages.

I checked all header files in the project for "defined variables", but found
none.
I only have "static const int..." statements, "extern int..." statements
with
"int..." statement in the corresponding *.c files and structure
definitions.

The errors do not occur without the -pm option.

Are there other reasons for this problem than variables that are defined in
multiple-included
header files ? How can I spot the problem ?

I appreciate your hints.
dorian

Dorian-

> first of all, before some people get nerved: yes, I used the search function
> and I also a read the threads concerning this topic =)
> ---
>
> When I turn on the -pm option, I get 76 link errors la:
>
> >> error: symbol _X is defined multiple times:
> Y.obj and common.obj
>
> X is always a function name, and Y is a source file name.
>
> The common.obj(includes most of the other .h files) is always mentioned in
> the
> error messages.
>
> I checked all header files in the project for "defined variables", but found
> none.
> I only have "static const int..." statements, "extern int..." statements
> with
> "int..." statement in the corresponding *.c files and structure
> definitions.
>
> The errors do not occur without the -pm option.
>
> Are there other reasons for this problem than variables that are defined in
> multiple-included
> header files ? How can I spot the problem ?
>
> I appreciate your hints.

Suggest to make a very small project with just a couple of source code files and try
with -pm. If it's something you're doing vs. a compiler/install issue or
command-line tools version conflict then it should be come clear.

-Jeff

PS. From my company e-address, I always get a bounce-back from redcodes.net. I can
send from a Yahoo address. If other people have that issue, it might be preventing
you from seeing all replies or seeing them in a timely manner. You might want to
look into that.
.DORIAN,

the -pm option causes the compiler to put all the programs together into a single 'module' and
then perform several optimizations, then perform the actual compile operation.

When you get a message that certain items are defined multiple times, that is exactly what it
means.
So, how can there be multiple definitions of a item?

Well, putting any definition in a header file, including #defines, const, etc.

To fix the problem, put all the actual data in specific .c files, not in any header file.

then put only 'extern' statements, typedef enum, typedef struct, typedef union, and 'function
prototypes' in any header files.

Also, do not define any data, nor initialize any data in the header files.
Put all the data initialization in an initialize() function, called from main() (or first thing in
main()) to do the data initializations.

Be very sure that any item that should only be visible in a single .c file contains the 'static'
modifier.

R. Williams
---------- Original Message -----------
From: ".dorian"
To:
Sent: Fri, 4 Jan 2008 15:36:39 +0800
Subject: [c6x] -pm option triggers "defined multiple times" link errors

> Hi guys,
>
> first of all, before some people get nerved: yes, I used the search function
> and I also a read the threads concerning this topic =)
> ---
>
> When I turn on the -pm option, I get 76 link errors la:
>
> >> error: symbol _X is defined multiple times:
> Y.obj and common.obj
>
> X is always a function name, and Y is a source file name.
>
> The common.obj(includes most of the other .h files) is always mentioned in
> the
> error messages.
>
> I checked all header files in the project for "defined variables", but found
> none.
> I only have "static const int..." statements, "extern int..." statements
> with
> "int..." statement in the corresponding *.c files and structure
> definitions.
>
> The errors do not occur without the -pm option.
>
> Are there other reasons for this problem than variables that are defined in
> multiple-included
> header files ? How can I spot the problem ?
>
> I appreciate your hints.
> dorian
------- End of Original Message -------
I am sure it's not a compiler issue since I have several smaller test
projects
that compile fine with -pm option enabled.

Dear Mister Williams, if I understood well, I have to move all "#define"
statements out of the
header files. Also normal macros ? that would be painful...

- "static inline" functions and "static const" data shouldn't cause any
problems, shouldn't they ?

- Let's say the linker tells me that function _X is defined multiple times
and the function X is defined in
Y.c and declared in Y.h. Does this mean that I have to change something
about function X in header file Y.h,
or can the problem be something else in some other header file ?
I ask because I have more than 25 header files, packed with code and going
trough all of them would take me days. So I try to find a way how to focus
the problematic code.

I am sorry for my retarded questions =)

Dorian
.dorian,

if function _x is defined multiple times..

is _x a function you wrote or a library function?

BTW you should never write a function that has leading underscore.
The compiler sets names by prepending a leading underscore, so there is one possible reason for the
duplicate defines.

Of course, in the whole project there should be only one instance of any one function name AND none
of the function names you wrote may be the same as anything in a library.

How about posting the source with the related errors.

simply paste all the above into a email should be plenty.

R. Williams

---------- Original Message -----------
From: ".dorian"
To:
Cc:
Sent: Sat, 5 Jan 2008 19:13:11 +0800
Subject: [c6x] Re: -pm option triggers "defined multiple times" link errors

> I am sure it's not a compiler issue since I have several smaller test
> projects
> that compile fine with -pm option enabled.
>
> Dear Mister Williams, if I understood well, I have to move all "#define"
> statements out of the
> header files. Also normal macros ? that would be painful...
>
> - "static inline" functions and "static const" data shouldn't cause any
> problems, shouldn't they ?
>
> - Let's say the linker tells me that function _X is defined multiple times
> and the function X is defined in
> Y.c and declared in Y.h. Does this mean that I have to change something
> about function X in header file Y.h,
> or can the problem be something else in some other header file ?
> I ask because I have more than 25 header files, packed with code and going
> trough all of them would take me days. So I try to find a way how to focus
> the problematic code.
>
> I am sorry for my retarded questions =)
>
> Dorian
------- End of Original Message -------
Dear Mister Williams,

function X is always one of my own functions and I didn't name them with
leading underscores.
I just wrote _X because the link error uses underscores in front of the
function names =)

In sum, I get 76 link errors ,one of them is:

>> error: symbol _x264_macroblock_encode_cache_end is defined multiple
times:
macroblock2.obj and common.obj
The function x264_macroblock_encode_cache_end is only defined once in
macroblock2.c
and declared once in macroblock2.h

I attached all the header files of the project in a .rar file, so maybe, if
you have a minute,
you can have a quick look at it.

Best regards and big thanks for your time guys !

Dorian
Hey community, Dear Mister Williams,

I have to apologize that I didn't read your message
carefully.

" the -pm option causes the compiler to put all the programs together into a
single 'module' and
then perform several optimizations, then perform the actual compile
operation."

Well, this means also that no longer single *.obj files are generated when
compiling, but only
one big *.obj file containing everything.

Since I didn't delete the old *.obj files (generated without -pm option
enabled), and
forgot to remove the corresponding lines in cmd file, most of the functions
were loaded
twice into memory.

cu
dorian
Dorian-

> Hey community, Dear Mister Williams,
>
> I have to apologize that I didn't read your message
> carefully.
>
> " the -pm option causes the compiler to put all the programs together into a
> single 'module' and
> then perform several optimizations, then perform the actual compile
> operation."
>
> Well, this means also that no longer single *.obj files are generated when
> compiling, but only
> one big *.obj file containing everything.
>
> Since I didn't delete the old *.obj files (generated without -pm option
> enabled), and
> forgot to remove the corresponding lines in cmd file, most of the functions
> were loaded
> twice into memory.

Ok, so you if you just mention the source files in the File View window, and not in
the .cmd file, then it should be Ok, right? Then you should be able to "toggle" the
-pm option within the project, as needed, and either way should build Ok.

-Jeff
Thanks for that information. Whenever you change a major program
setting that may not change each individual file, it's a good idea to do
a "build clean" or a "rebuild all".

.dorian wrote:
> Hey community, Dear Mister Williams,
>
> I have to apologize that I didn't read your message
> carefully.
>
> " the -pm option causes the compiler to put all the programs together into a
> single 'module' and
> then perform several optimizations, then perform the actual compile
> operation."
>
> Well, this means also that no longer single *.obj files are generated when
> compiling, but only
> one big *.obj file containing everything.
>
> Since I didn't delete the old *.obj files (generated without -pm option
> enabled), and
> forgot to remove the corresponding lines in cmd file, most of the functions
> were loaded
> twice into memory.
>
> cu
> dorian
>
>
Check Out Industrys First Single-Chip, Multi-Format, Real-Time HD Video Transcoding Solution for Commercial & Consumer End Equipment: www.ti.com/dm6467

Dorian and others who might use -pm,

On Jan 8, 2008 8:54 AM, Jeff Brower wrote:
> Dorian-
> > Hey community, Dear Mister Williams,
> >
> > I have to apologize that I didn't read your message
> > carefully.
> >
> > " the -pm option causes the compiler to put all the programs together
> into a
> > single 'module' and
> > then perform several optimizations, then perform the actual compile
> > operation."
> >
> > Well, this means also that no longer single *.obj files are generated
> when
> > compiling, but only
> > one big *.obj file containing everything.

FYI - Read the manual [spru187] on -pm.
When you use file specific compiler settings [I think you may have
mentioned] those files are excluded from the group.
-pm is a very powerful option, but your code should be totally
debugged and 'clean' before attempting to use it. Poor coding that
'pretty much works' when unoptimized can generate some very difficult
to debug problems when built with -pm.

mikedunn
> >
> > Since I didn't delete the old *.obj files (generated without -pm option
> > enabled), and
> > forgot to remove the corresponding lines in cmd file, most of the
> functions
> > were loaded
> > twice into memory.
>
> Ok, so you if you just mention the source files in the File View window,
> and not in
> the .cmd file, then it should be Ok, right? Then you should be able to
> "toggle" the
> -pm option within the project, as needed, and either way should build Ok.
>
> -Jeff
>

--
www.dsprelated.com/blogs-1/nf/Mike_Dunn.php
Check Out Industrys First Single-Chip, Multi-Format, Real-Time HD Video Transcoding Solution for Commercial & Consumer End Equipment: www.ti.com/dm6467