[CMake] Linking problem

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


On 11/7/07, Renaud Detry <renaudjdetry at airpost.net> wrote:
>
> On 07 Nov 2007, at 11:35, Salvatore Iovene wrote:
>
> > 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.
>
> Then why don't you build all objects from foo, a, b, c to be PIC and
> pack them all together in foo? Or if you really want intermediate
> archives, maybe you can build the objects of a, b, c to be PIC,
> archive them in .a archives, and use ld to put them together. But this
> is not the same thing as linking foo to a, b, c using gcc and -la -lb
> -lc, which means to only fetch needed symbols.
>
> The bottom line is, what you mean to do is probably not very common,
> and I don't think there will be a high-level CMake primitive that will
> do that for you.
>
> This is just my opinion though :-)

What do you mean by PIC?
Thanks!

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