This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Problem linking to wrong class
- From: Ian Lance Taylor <iant at google dot com>
- To: Brian Peschel <brianp at occinc dot com>
- Cc: "John \(Eljay\) Love-Jensen" <eljay at adobe dot com>, GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 20 Apr 2009 20:49:15 -0700
- Subject: Re: Problem linking to wrong class
- References: <C6123147.3A4AA%eljay@adobe.com> <49ECC9D4.5060204@occinc.com>
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