This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem linking to wrong class



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]