CodeWarrior Linux and ld error messages

CodeWarrior Linux and ld error messages

Post by Peter Mantel » Sat, 14 Apr 2001 07:04:43



I received a lovely copy of Metrowerks CW 6.0 Linux Edition by courier
today....mmmmm..

But when building an OpenGL app which used to compile, link & work fine
with my Makefile which I used to use, I received about 148 errors.

I've now managed to get it down to 1 error, but don't understand enough
about what it means in order to sort it out. The message is:

Link error:  model.c.o (.data+0x0): multiple definition of
'lightposition'
grow.c.o (.data+0x24): first defined here
model.c.o (.data+0x10): multiple definition of 'lightdirection'
grow.c.o (.data+0x34): first defined here
model.c.o (.data+0x1c): multiple definition of 'grnd'
grow.c.o (.data+0x40): first defined here
collect2: ld returned exit 1 status
collect2: ld returned exit 1 status

The three variables that it refers to are defined (ONCE) in model.h (not
model.c) and nowhere else. I've spent hours trying to figure this out,
and I think the cheif problem is that I don't quite understand how
CodeWarrior is linking all this stuff together.

Can anyone help me figure out what's going on here? Or at least point me
to a document which explains ld's error messages, because it's driving
me nuts.

Would it be better if I uninstalled CodeWarrior and installed it with
the GCC version that comes with it? I am using version 2.95.3 and I
believe that the version that comes with it is 2.95.2.

Thanks in anticipation,

Peter Mantell

--

"Life would be so much easier if we could just look at the source code."

       -- Dave Olson

 
 
 

CodeWarrior Linux and ld error messages

Post by Nate Eldredg » Sat, 14 Apr 2001 08:53:52



> I received a lovely copy of Metrowerks CW 6.0 Linux Edition by courier
> today....mmmmm..

> But when building an OpenGL app which used to compile, link & work fine
> with my Makefile which I used to use, I received about 148 errors.

> I've now managed to get it down to 1 error, but don't understand enough
> about what it means in order to sort it out. The message is:

> Link error:  model.c.o (.data+0x0): multiple definition of
> 'lightposition'
> grow.c.o (.data+0x24): first defined here
> model.c.o (.data+0x10): multiple definition of 'lightdirection'
> grow.c.o (.data+0x34): first defined here
> model.c.o (.data+0x1c): multiple definition of 'grnd'
> grow.c.o (.data+0x40): first defined here
> collect2: ld returned exit 1 status
> collect2: ld returned exit 1 status

> The three variables that it refers to are defined (ONCE) in model.h (not
> model.c) and nowhere else. I've spent hours trying to figure this out,

That is your problem.  You presumably include model.h in several
different source files, so your variable ends up being defined in each
of these.  The definition SHOULD be in a .c file so that it only ends
up in the final program once.  The header should contain only a
declaration.  Example:

model.h:
extern sometype lightdirection;

model.c:
sometype lightdirection = INITIAL_VALUE;

Quote:> and I think the cheif problem is that I don't quite understand how
> CodeWarrior is linking all this stuff together.

> Can anyone help me figure out what's going on here? Or at least point me
> to a document which explains ld's error messages, because it's driving
> me nuts.

> Would it be better if I uninstalled CodeWarrior and installed it with
> the GCC version that comes with it? I am using version 2.95.3 and I
> believe that the version that comes with it is 2.95.2.

Probably doesn't make much difference, as far as this is concerned.

--

Nate Eldredge


 
 
 

CodeWarrior Linux and ld error messages

Post by Peter Mantel » Sat, 14 Apr 2001 20:32:59


Quote:> That is your problem.  You presumably include model.h in several
> different source files, so your variable ends up being defined in each
> of these.

Yeah, I did have it included several times, but I thought that wrapping
the entire .h file in

#ifndef MODEL_H
#define MODEL_H

...

#endif

would cater for that problem.

Quote:>  The definition SHOULD be in a .c file so that it only ends
> up in the final program once.  The header should contain only a
> declaration.  Example:

> model.h:
> extern sometype lightdirection;

> model.c:
> sometype lightdirection = INITIAL_VALUE;

But that makes much more sense. Thanks Nate.
 
 
 

CodeWarrior Linux and ld error messages

Post by Guy Rouilli » Wed, 18 Apr 2001 22:55:44


The sentinals are defined only for a single compilation unit.  So if
you compile a.c that #include "model.h" and then compile b.c that does
the same, model.h will get included in both because the sentinal only
becomes defined for the duration of a single compilation unit. a.c and
b.c are different compilation units.


>> That is your problem.  You presumably include model.h in several
>> different source files, so your variable ends up being defined in each
>> of these.

>Yeah, I did have it included several times, but I thought that wrapping
>the entire .h file in

>#ifndef MODEL_H
>#define MODEL_H

>...

>#endif

>would cater for that problem.

>>  The definition SHOULD be in a .c file so that it only ends
>> up in the final program once.  The header should contain only a
>> declaration.  Example:

>> model.h:
>> extern sometype lightdirection;

>> model.c:
>> sometype lightdirection = INITIAL_VALUE;

>But that makes much more sense. Thanks Nate.

=============================
Guy Rouillier
 
 
 

CodeWarrior Linux and ld error messages

Post by Peter Mantel » Thu, 19 Apr 2001 06:46:44



> The sentinals are defined only for a single compilation unit.  So if
> you compile a.c that #include "model.h" and then compile b.c that does
> the same, model.h will get included in both because the sentinal only
> becomes defined for the duration of a single compilation unit. a.c and
> b.c are different compilation units.

That fits with what I'm seeing, but then leads me to another question.
I've seen people put these sentinels in code before: what purpose do
they serve?
 
 
 

CodeWarrior Linux and ld error messages

Post by MWRo » Thu, 19 Apr 2001 12:25:46





>> The sentinals are defined only for a single compilation unit.  So if
>> you compile a.c that #include "model.h" and then compile b.c that does
>> the same, model.h will get included in both because the sentinal only
>> becomes defined for the duration of a single compilation unit. a.c and
>> b.c are different compilation units.

>That fits with what I'm seeing, but then leads me to another question.
>I've seen people put these sentinels in code before: what purpose do
>they serve?

The difference is a translation unit  ( the source file and all files
included in it directly or indirectly ) and linking.

It is often common for the one source file to include several header
files.  These header files may then include the same header file.  This
use prevents redeclaration errors or redefinition errors that would
otherwise be ran into.

However the translation unit is compiled into an object code with each
of those defines and in those object files.  When you link these object
files to create an application you then get the redefintiion errors.

Now there is a way around this with CodeWarrior.

If you precompile your headers it creates one global header that is
included in each target for resolving the compiler but it is global and
only included once in a target.   You can also add the include statement
sin a prefix file as well.  It works the same way.

Ron

--
 News Flash !!  CodeWarrior U Now Offering PowerPlant Courses

Visit the world's largest site for free programmer training
Embedded - Macintosh - Windows - coming soon Palm Platform
              http://www.codewarrioru.com/    


ks.com

 
 
 

CodeWarrior Linux and ld error messages

Post by Peter Mantel » Thu, 19 Apr 2001 19:07:57


Quote:> If you precompile your headers it creates one global header that is
> included in each target for resolving the compiler but it is global and
> only included once in a target.   You can also add the include statement
> sin a prefix file as well.  It works the same way.

How'd you do that then?
 
 
 

CodeWarrior Linux and ld error messages

Post by MWRo » Fri, 20 Apr 2001 00:25:11




Quote:>> If you precompile your headers it creates one global header that is
>> included in each target for resolving the compiler but it is global and
>> only included once in a target.

I'm sorry this doesn't seem to apply,  It looks like the GNU compilers
can't pre-compile headers

Quote:>>   You can also add the include statement
>> sin a prefix file as well.  It works the same way.

I love spell checkers :)   it should be ...statements in...

Quote:>How'd you do that then?

You just Create a file, it can include any C or C++ statement that does
not generate code.  For example you could define DebugTest for
conditions.   You then type in the name of this file in your Project
Settings : Language Settings : GNU Compiler  for the Prefix File.

Ron

--
** News Flash **  CodeWarrior U Now Offering PowerPlant Courses

Visit the world's largest site for free programmer training
Embedded - Macintosh - Windows - coming soon Palm Platform
              http://www.codewarrioru.com/    


ks.com

 
 
 

1. ld error message

What does the following error message mean, and is there any way to recover?
Can we avoid it in the future?

ld fatal: can't read archive string table of archive pspopsim/pslib

We are building a very large program (over 1MB) and the library which we build
is about 1.5MB.

Any help would be appreciated. Thanks!!
--------------------------------------------------------------------------
Al Kiecker                      UUCP:   mecc!herman!alan
Unisys - Computer Systems Div.          ihnp4!{bonnie,clyde}!herman!alan
Eagan,MN                                mecc!emspxnx!alan
(612)681-6475

2. C Programmers needed -- ORLANDO, FLORIDA

3. "ld.so.cache is corrupt" error message

4. WIN NT; WIN 95; LINUX

5. g++(egcs)/ld error message

6. Dell P90: help linux install on 540 Meg Drive

7. ld.so error message

8. Pager for Linux?

9. ld error message: Concatenated objects - what does it mean?

10. cryptic ld error message

11. Error message continuous error messages

12. compiling programs to use ld-linux.so.1 instead of ld-linux.so.2

13. Matrox Mystique ands X.