C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

wrong link to destructor

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
scl@ict.ac.cn
Guest





PostPosted: Sat Mar 19, 2005 1:02 am    Post subject: wrong link to destructor Reply with quote



there are two class with same name in an ugly program:

a.so
class REGION {

....
~REGION(){...}
}

b.so
class REGION {
....
~REGION(){}
}

where a.so's ~REGION is linked to b.so's ~REGION.

if i move the defination of ~REGION in a.so to a .cxx file, the ~REGION
in b.so will be linked to the ~REGION in a.so

what's wrong?
how to fixed?
(rename is NOT a practical idea!)


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ron Natalie
Guest





PostPosted: Sat Mar 19, 2005 10:46 am    Post subject: Re: wrong link to destructor Reply with quote



[email]scl (AT) ict (DOT) ac.cn[/email] wrote:

Quote:
what's wrong?

Violation of the One Definition Rule.

Quote:
how to fixed?
(rename is NOT a practical idea!)

rename is the only portable answer. Either change one or the other
or put it in a namespace to disambiguate it.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
codigo
Guest





PostPosted: Sun Mar 20, 2005 11:56 pm    Post subject: Re: wrong link to destructor Reply with quote




"scl (AT) ict (DOT) ac.cn" <sangchunlei (AT) gmail (DOT) com> wrote

Quote:
there are two class with same name in an ugly program:

That breaks a fundamental rule. Say you declare:

Region region;

Which implementation should be called?

Quote:

a.so
class REGION {

...
~REGION(){...}
}

b.so
class REGION {
...
~REGION(){}
}

where a.so's ~REGION is linked to b.so's ~REGION.

That's impossible.

Quote:

if i move the defination of ~REGION in a.so to a .cxx file, the ~REGION
in b.so will be linked to the ~REGION in a.so

what's wrong?
how to fixed?
(rename is NOT a practical idea!)

Yes it is, use namespaces to seperate the decarations / implementations.

namespace A
{
class Region
{
....
};
};

namespace B
{
class Region
{
....
};
};


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Mon Mar 21, 2005 9:51 pm    Post subject: Re: wrong link to destructor Reply with quote

[email]scl (AT) ict (DOT) ac.cn[/email] wrote:
Quote:
there are two class with same name in an ugly program:

a.so
class REGION {

...
~REGION(){...}
}

b.so
class REGION {
...
~REGION(){}
}

where a.so's ~REGION is linked to b.so's ~REGION.

if i move the defination of ~REGION in a.so to a .cxx file,
the ~REGION in b.so will be linked to the ~REGION in a.so

what's wrong?
how to fixed?
(rename is NOT a practical idea!)

This isn't actually a C++ problem (since C++ doesn't have shared
objects), and is very dependant on the implementation. Since
you speak of .so files, I will suppose Posix, where the answer
is to pass the RTLD_LOCAL flag to dlopen when you load the
objects.

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ben Hutchings
Guest





PostPosted: Tue Mar 22, 2005 9:07 am    Post subject: Re: wrong link to destructor Reply with quote

[email]scl (AT) ict (DOT) ac.cn[/email] wrote:
Quote:
there are two class with same name in an ugly program:

a.so
class REGION {

...
~REGION(){...}
}

b.so
class REGION {
...
~REGION(){}
}

where a.so's ~REGION is linked to b.so's ~REGION.

if i move the defination of ~REGION in a.so to a .cxx file, the ~REGION
in b.so will be linked to the ~REGION in a.so

what's wrong?

In a standard C++ program, there must only be one definition of a
named entity with external linkage. Unix dynamic linking normally
emulates static linking, so that this rule applies throughout all
shared objects. If the rule is violated, anything can happen.

Quote:
how to fixed?
(rename is NOT a practical idea!)

You need to limit which symbols are exported. This is outside the
scope of standard C++. You may find section 2.2 of
<http://people.redhat.com/drepper/dsohowto.pdf> helpful.

--
Ben Hutchings
Having problems with C++ templates? Your questions may be answered by
<http://womble.decadentplace.org.uk/c++/template-faq.html>.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.