Linkage errors after function rename

R

RK

I renamed a function in one of my files, and got this error (gcc
4.0.1, Apple build 5367)--

c++ -O2 -o cantilever Force.cpp Beam.cpp CantileverNl.cpp main.cpp
/usr/bin/ld: multiple definitions of symbol CantileverNl::G(double)
/var/tmp//ccOkSPin.o definition of CantileverNl::G(double)in section
(__TEXT,__text)
/var/tmp//ccEdCBIJ.o definition of CantileverNl::G(double)in section
(__TEXT,__text)
/usr/bin/ld: multiple definitions of symbol __ZN12CantileverNl1GEd.eh
/var/tmp//ccOkSPin.o definition of absolute __ZN12CantileverNl1GEd.eh
(value 0x0)
/var/tmp//ccEdCBIJ.o definition of absolute __ZN12CantileverNl1GEd.eh
(value 0x0)


I couldn't find any multiple definitions. I tried changing my function
name, changing my directory, clearing /var/tmp, and rewriting my
Makefile; none of these approaches worked. However, a compilation
with Xcode returned no errors and actually went on to execute the
program successfully. Do any of you know what's happening?
 
A

Alf P. Steinbach

* RK:
I renamed a function in one of my files, and got this error (gcc
4.0.1, Apple build 5367)--

c++ -O2 -o cantilever Force.cpp Beam.cpp CantileverNl.cpp main.cpp
/usr/bin/ld: multiple definitions of symbol CantileverNl::G(double)
/var/tmp//ccOkSPin.o definition of CantileverNl::G(double)in section
(__TEXT,__text)
/var/tmp//ccEdCBIJ.o definition of CantileverNl::G(double)in section
(__TEXT,__text)
/usr/bin/ld: multiple definitions of symbol __ZN12CantileverNl1GEd.eh
/var/tmp//ccOkSPin.o definition of absolute __ZN12CantileverNl1GEd.eh
(value 0x0)
/var/tmp//ccEdCBIJ.o definition of absolute __ZN12CantileverNl1GEd.eh
(value 0x0)


I couldn't find any multiple definitions. I tried changing my function
name, changing my directory, clearing /var/tmp, and rewriting my
Makefile; none of these approaches worked. However, a compilation
with Xcode returned no errors and actually went on to execute the
program successfully. Do any of you know what's happening?

It seems you have placed the definition of the CantileverNl::G(double)
member function in a header file, outside the class definition, without
adding "inline", and included that header file directly or indirectly in
files [OkSpin.cpp] and [EdCBIJ.cpp].

Judging from the compiler's error messages, that is.

The renaming may possibly have nothing to do with this error.


Cheers, & hth.,

- Alf
 
R

raghukumar

* RK:


I renamed a function in one of my files, and got this error (gcc
4.0.1, Apple build 5367)--
c++ -O2 -o cantilever Force.cpp Beam.cpp CantileverNl.cpp main.cpp
/usr/bin/ld: multiple definitions of symbol CantileverNl::G(double)
/var/tmp//ccOkSPin.o definition of CantileverNl::G(double)in section
(__TEXT,__text)
/var/tmp//ccEdCBIJ.o definition of CantileverNl::G(double)in section
(__TEXT,__text)
/usr/bin/ld: multiple definitions of symbol __ZN12CantileverNl1GEd.eh
/var/tmp//ccOkSPin.o definition of absolute __ZN12CantileverNl1GEd.eh
(value 0x0)
/var/tmp//ccEdCBIJ.o definition of absolute __ZN12CantileverNl1GEd.eh
(value 0x0)
I couldn't find any multiple definitions. I tried changing my function
name, changing my directory, clearing /var/tmp, and rewriting my
Makefile; none of these approaches worked. However, a compilation
with Xcode returned no errors and actually went on to execute the
program successfully. Do any of you know what's happening?

It seems you have placed the definition of the CantileverNl::G(double)
member function in a header file, outside the class definition, without
adding "inline", and included that header file directly or indirectly in
files [OkSpin.cpp] and [EdCBIJ.cpp].

Judging from the compiler's error messages, that is.

The renaming may possibly have nothing to do with this error.

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Hi Alf,
can you please explain me, why you thought it should work if you
define CantileverNl::G(double)
this with inline? (i am unable to understand that's why?).
 
A

Alf P. Steinbach

* raghukumar:
* RK:


I renamed a function in one of my files, and got this error (gcc
4.0.1, Apple build 5367)--
c++ -O2 -o cantilever Force.cpp Beam.cpp CantileverNl.cpp main.cpp
/usr/bin/ld: multiple definitions of symbol CantileverNl::G(double)
/var/tmp//ccOkSPin.o definition of CantileverNl::G(double)in section
(__TEXT,__text)
/var/tmp//ccEdCBIJ.o definition of CantileverNl::G(double)in section
(__TEXT,__text)
/usr/bin/ld: multiple definitions of symbol __ZN12CantileverNl1GEd.eh
/var/tmp//ccOkSPin.o definition of absolute __ZN12CantileverNl1GEd.eh
(value 0x0)
/var/tmp//ccEdCBIJ.o definition of absolute __ZN12CantileverNl1GEd.eh
(value 0x0)
I couldn't find any multiple definitions. I tried changing my function
name, changing my directory, clearing /var/tmp, and rewriting my
Makefile; none of these approaches worked. However, a compilation
with Xcode returned no errors and actually went on to execute the
program successfully. Do any of you know what's happening?
It seems you have placed the definition of the CantileverNl::G(double)
member function in a header file, outside the class definition, without
adding "inline", and included that header file directly or indirectly in
files [OkSpin.cpp] and [EdCBIJ.cpp].

Judging from the compiler's error messages, that is.

The renaming may possibly have nothing to do with this error.

Hi Alf,
can you please explain me, why you thought it should work if you
define CantileverNl::G(double)
this with inline? (i am unable to understand that's why?).

Please don't quote signatures, see the FAQ, corrected.

I don't think "it should work" if you define the function inline.

I wrote that the judging from the compiler's error messages, you have
placed the function non-inline in a header file. That can easily cause
multiple definitions of the same function. The compiler's error message
is about multiple definitions.

C++ inline allows the same function to be defined the same way in
multiple compilation units.

It must then be inline in all compilation units where it's used.

Cheers, & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top