[CMake] Linking problem

Salvatore Iovene salvatore.iovene+cmake at googlemail.com
Wed Nov 7 05:35:25 EST 2007


On 11/7/07, Renaud Detry <renaudjdetry at airpost.net> wrote:
>
> On 07 Nov 2007, at 11:04, Salvatore Iovene wrote:
>
> > On 11/7/07, Renaud Detry <renaudjdetry at airpost.net> wrote:
> >>
> >> On 07 Nov 2007, at 09:59, Salvatore Iovene wrote:
> >>
> >>> On 11/7/07, Brandon Van Every <bvanevery at gmail.com> wrote:
> >>>> On Nov 7, 2007 2:12 AM, Salvatore Iovene
> >>>> <salvatore.iovene+cmake at googlemail.com> wrote:
> >>>>> Hi,
> >>>>> I'm not 100% sure this is really a CMake related question, but
> >>>>> I'll
> >>>>> fire it up anyway:
> >>>>>
> >>>>> I'm building a series of static libraries, name them liba.a,
> >>>>> libb.a
> >>>>> and libc.a, and linking them into a shared library libfoo.so.
> >>>>>
> >>>>> Then I'm building libx.a liby.a and libz.a and linking them
> >>>>> into the
> >>>>> shared libbar.so.
> >>>>>
> >>>>> Then I have an executable whatever.exe that's linked to to
> >>>>> libfoo.so
> >>>>> and libbar.so. The linking of the executable fails complaining of
> >>>>> certain missing simbols. Some symbols from liba.a are missing in
> >>>>> libbar.so.
> >>
> >> Let's say that there's a symbol S in liba.a, that S is the only
> >> symbol
> >> in its object, and that S is not used by libfoo. In Darwin, S will
> >> not
> >> be included in libfoo, and the result you get is expectable. I don't
> >> know if this simple explanation translates to Linux.
> >
> > I don't know either, but that seems to be the case. Any ideas on
> > how to fix it?
>
> IMHO, you shouldn't use symbols from liba in libbar if libbar doesn't
> link against liba.
>
> I think you could do either of
>
> 1.- make all your static libs dynamic, and link libbar against liba if
>      libbar uses symbols from liba.
>
> 2.- link neither libfoo nor libbar to liba, but link whatever.exe to
>      liba. This will require an extra flag about undefined symbols
>      under Darwin, but I don't think ld will complain under Linux.
>
> Option (1) seems far nicer to me.
>
> Hope this helps.
> Renaud.

Thanks. Your options seem very reasonable. The thing is, though, that
the various liba, libb, libc were meant to be only used to build a
bigger library called libfoo. So what I really want is that symbols in
liba are defined in libfoo even if libfoo doesn't use them.

Does it make sense?

-- 
Salvatore Iovene
http://www.iovene.com/
Key Fingerprint: 5647 944D D5AD 2E87 00B4  7D54 2864 359D FF20 16D8


More information about the CMake mailing list