------- Additional Comments From matz at suse dot de  2005-07-27 13:46 -------
Because these symbols indeed are not defined anywhere.  On linux this happens   
to work, but on darwin you need to link against something which provides them.  
  
So you would need to create a library which implements both operators  
out-of-line (and hence also the vtable), and us that to link _this_ library  
against.  
 
But that's not the issue at hand. 
  
This is the bigger picture, how this error can be seen in the real world: 
First, there is a base library (let's call it libbase) implementing the  
whole class, all methods, the vtable, everything.  
  
Then there's another library (libtwo), using that class in implementing some  
of it's functionality (breakme in our case).  It does so by including the  
header for that class (defining the inline operator !=, besides declaring  
the class), and linking against libbase.  Hence no unresolved symbols will  
occur.  
  
The libtwo exports only those symbols and class it wants exported, hence  
it switches the default visibility to hidden (including inlines), because all  
these are already defined in libbase, no need to export them too.  
  
This is all perfectly valid usage of shared libs.  But it doesn't work because  
libtwo can't be created due to the invalid call emitted to a method not  
defined in the same DSO.  
  
Perhaps I should have made more clear the bigger picture to not sidetrack  
others by the undefinedness of operator==.  In the real world it _will_ be  
defined, in a different shared lib.  So just for reference a little bit 
reformatted: 
 
--------------- libbase.ii -------------------- 
struct A { 
  virtual bool operator== (const A &a) const; 
  virtual bool operator!= (const A &a) const; 
}; 
inline bool A::operator!= ( const A &a) const 
{ return !(*this == a); } 
bool A::operator== (const A&a) const 
{ return true; } 
----------------------------------------------- 
 
Compile this with just "g++ -fPIC -shared -o libbase.so libbase.ii", and 
you have a shared lib you can use to link against when creating the 
second shared lib, from the source of the initial report here.  Note that 
the first few lines (including definition of operator !=) reflect a 
header file which declares class A, which is included in libbase.ii and 
testcase.ii. 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22592

Reply via email to