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


Brian Peschel <brianp@occinc.com> writes:

>> 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?

Use the -Bsymbolic linker option.


> 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).

That is expected if the static library has a function named
SqlQuery::runit().  And if the static library does have such a function,
you've violated the One Definition Rule.

Ian


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