Problem linking to wrong class

Brian Peschel brianp@occinc.com
Mon Apr 20 19:15:00 GMT 2009


John (Eljay) Love-Jensen wrote:
> Hi Brian,
>
> When you link against the static library, any missing symbols cause the
> providing ³.o² in the ³.a² static library to be linked into your executable.
>   
I have other programs that use the shared library (libtwo.so) and not 
the static library (libone.a), so there should not be any missing symbols.

> My guess is that the libtwo.so is using the symbols linked into your
> executable that became part of your executable from libone.a.  Those
> executable symbols are preferential, even over the self-same symbols in
> libtwo.so.
>   
They aren't preferential in this situation :)
> One way around the issue is called ³early binding².  You could build
> libtwo.so such that it binds to its own symbols, rather than allowing the
> loader to resolve the unbound symbols with the ones provided by your
> executable.
>   
Is there a way to force the compiler/linker to do this?  From what I see 
doing a google search for early binding, I should already be doing it.  
I am not using any function pointers here.  I have something like this 
in the shared library (libtwo.so), obviously, I have removed stuff:

void something()
{
  TheQuery query;
  query.doThis();
}

class TheQuery
{
private:
  SqlQuery* query;
public:
  TheQuery()

  void doThis() {query->runIt();}
}


class SqlQuery
{
private:
  clear();
  run();
  stop();
public:
  SqlQuery();

  void runIt() {clear(); run(); stop();}
}

But when it calls runIt() it is calling the one in the static (libone.a).

- Brian



More information about the Gcc-help mailing list