linking with frameworks and C++ static libraries

  • Can anybody help with the following issue:



    I have a large Cocoa/Objective-C++ application that has several custom
    Objective-C++ frameworks and several C++ static libraries.  The problem is
    that both the main application itself and one of the frameworks it uses
    directly link against some of the same C++ static libraries.  While this
    seems to compile, I'm concerned that I'm getting multiple copies of the
    static libraries linked in.



    What I'd like to do is link the C++ static libraries only into the
    framework, and have the application only link against the framework - with
    the app getting the C++ static library symbols indirectly through the
    framework.  Is this possible?  When I try it, I just get undefined symbol
    linker errors because the main application can't "see" the C++ static
    library symbols through the framework.  Is there an easy way to have the
    framework re-export those symbols (and not dead-strip symbols not used
    directly by the framework) to accomplish what I want?



    (I know this issue could be resolved by converting the C++ static libraries
    to dynamic libraries, but I'm trying to avoid that for other reasons.)



    Thanks,

    -John
  • John:

    > I have a large Cocoa/Objective-C++ application that has several custom =
    =20
    > Objective-C++ frameworks and several C++ static libraries.=A0 The =20
    > problem is that both the main application itself and one of the =20
    > frameworks it uses directly link against some of the same C++ static =20=

    > libraries.=A0 While this seems to compile, I'm concerned that I'm =20
    > getting multiple copies of the static libraries linked in.

    I don't think you should be worried. According to:

    file:///Developer/Documentation/DeveloperTools/gcc-3.3/gcc/C-Dialect-=20
    Options.html#C%20Dialect%20Options

    the option -fcoalesce does coalesce duplicated functions and data and =20=

    is enabled by default. Since it says "the linker will discard all but =20=

    one", it must mean that statically linked duplicates are discarded.

    I suggest you experiment if you are unsure e.g. create a static library =20=

    with 100K of dummy code in a single function. Create a simple framework =20=

    using that, and an application using that and the framework. Is the =20
    result > 200K?

    > What I'd like to do is link the C++ static libraries only into the =20
    > framework, and have the application only link against the framework - =20=

    > with the app getting the C++ static library symbols indirectly through =
    =20
    > the framework.=A0 Is this possible?=A0 When I try it, I just get =
    undefined =20
    > symbol linker errors because the main application can't "see" the C++ =20=

    > static library symbols through the framework.=A0 Is there an easy way =
    to =20
    > have the framework re-export those symbols (and not dead-strip symbols =
    =20
    > not used directly by the framework) to accomplish what I want?

    Strangely enough, according to:

    file:///Developer/Documentation/Essentials/Performance/Languages/=20
    Automated_C_ptimization.html

    the current OS X tools do not dead strip linked code. If the linker =20
    really does not dead strip but does coalesce symbols, you would expect =20=

    that unused symbols that are not duplicated are kept, but used symbols =20=

    that are duplicated are reduced to a single copy.

    Cheers, Glen Low

    ---
    pixelglow software | simply brilliant stuff
    www.pixelglow.com=
  • Glen,

    Thanks for the info and documentation pointers.  That does make me

    less worried about duplicate functions/data, but it does not

    fundamentally solve my real issue -- and the statement in the

    documentation about GCC on OSX not dead stripping linked code is

    puzzling.  Let me explain:



    I actually have multiple C++ static libraries, one "independent"

    Objective-C++ framework, several other Objective-C++ frameworks

    dependent on the first, and several apps dependent on all the

    libraries/frameworks.  What I would really like to do is simply link

    all the C++ static libraries into the one "independent" framework, and

    then have all the other dependent frameworks/apps get the all the C++

    static library symbols through the first framework (which everything

    else links against).



    The problem, as I seem to have verified with "nm", is that most of the

    symbols from the C++ static libraries seem to be removed from the

    symbol table of the first framework after it's linked.  It appears as

    though they are being "dead stripped" from the framework's internal

    dylib when it is linked, so I just get undefined symbol linker errors

    when I build the other frameworks/apps unless I explicitly link the

    C++ static libraries into them as well.  And nothing I've tried, after

    numerous Google searches, makes any difference.



    I would really like to find a way to force the first framework to

    preserve (re-export) the symbols from the C++ static libraries so I

    don't need to explicitly link the C++ static libraries into all the

    other projects.  I'm using the latest Jaguar Dev tools (ProjectBuilder

    2.1) on MacOSX 10.2.8 with the August 2003 GCC 3.3 update.



    Thanks in advance for any additional insight anyone can offer on this issue.

    -John





    > On Sunday, October 26, 2003, at 01:44  AM, Glen Low wrote:

    >

    >> John:

    >>

    >>

    >>> I have a large Cocoa/Objective-C++ application that has several custom

    >>> Objective-C++ frameworks and several C++ static libraries.  The

    >>> problem is that both the main application itself and one of the

    >>> frameworks it uses directly link against some of the same C++ static

    >>> libraries.  While this seems to compile, I'm concerned that I'm

    >>> getting multiple copies of the static libraries linked in.

    >>>

    >>>

    >> I don't think you should be worried. According to:

    >>

    >>
    file:///Developer/Documentation/DeveloperTools/gcc-3.3/gcc/C-Dialect-Options
    .html#C%20Dialect%20Options

    >>

    >> the option -fcoalesce does coalesce duplicated functions and data and is

    >> enabled by default. Since it says "the linker will discard all but one",

    >> it must mean that statically linked duplicates are discarded.

    >>

    >> I suggest you experiment if you are unsure e.g. create a static library

    >> with 100K of dummy code in a single function. Create a simple framework

    >> using that, and an application using that and the framework. Is the
    result > 200K?

    >>

    >>

    >>> What I'd like to do is link the C++ static libraries only into the

    >>> framework, and have the application only link against the framework -

    >>> with the app getting the C++ static library symbols indirectly through

    >>> the framework.  Is this possible?  When I try it, I just get undefined

    >>> symbol linker errors because the main application can't "see" the C++

    >>> static library symbols through the framework.  Is there an easy way to

    >>> have the framework re-export those symbols (and not dead-strip symbols

    >>> not used directly by the framework) to accomplish what I want?

    >>>

    >>>

    >> Strangely enough, according to:

    >>

    >>
    file:///Developer/Documentation/Essentials/Performance/Languages/Automated_C
    _ptimization.html

    >>

    >> the current OS X tools do not dead strip linked code. If the linker

    >> really does not dead strip but does coalesce symbols, you would expect

    >> that unused symbols that are not duplicated are kept, but used symbols

    >> that are duplicated are reduced to a single copy.

    >>

    >>

    >> Cheers, Glen Low

    >>

    >> ---

    >> pixelglow software | simply brilliant stuff

    >> www.pixelglow.com

    >
  • On Monday, October 27, 2003, at 01:41  pm, John DeNisi wrote:

    > Glen,
    >
    > Thanks for the info and documentation pointers.=A0 That does make me
    > less worried about duplicate functions/data, but it does not=A0
    > fundamentally solve my real issue -- and the statement in the=A0
    > documentation about GCC on OSX not dead stripping linked code is=A0
    > puzzling.=A0 Let me explain:
    >
    > I actually have multiple C++ static libraries, one "independent"
    > Objective-C++ framework, several other Objective-C++ frameworks
    > dependent on the first, and several apps dependent on all the
    > libraries/frameworks.=A0 What I would really like to do is simply =
    link=A0
    > all the C++ static libraries into the one "independent" framework, =
    and=A0
    > then have all the other dependent frameworks/apps get the all the C++=A0=

    > static library symbols through the first framework (which everything=A0
    > else links against).

    Have you read

    http://developer.apple.com/documentation/Porting/Conceptual/=20
    PortingUnix/compiling/chapter_4_section_5.html

    It sounds like you might be falling foul of the two-level namespace =20
    feature.

    Kind regards,

    Alastair.
previous month october 2003 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today