static linking of C++ libraries with gcc/g++

Discussion in 'C++' started by daniel_shaw01@excite.com, Jan 6, 2005.

  1. Guest

    I want to link the C++ standard libraries statically for my application
    because I don't space for the .so files on my target platform.

    After quite a bit of searching, I found very little information that
    was helpful. The best information I found was at this link
    http://fresco.org/~njs/c -without-stdc

    I followed the approach here and used -nostdlib to disable the default
    linking. Instead I use the options:

    -lsupc++ -lgcc -lgcc_eh -lc -lgcc -lgcc_eh

    where -lgcc -lgcc_eh has to be repeated twice for some reason.

    In summary the linker options I used are

    -Wl,-Bstatic -lsupc++ -lgcc -lgcc_eh -lc -lgcc -lgcc_eh

    followed by -Wl,-Bdynamic to link dynamically with some other
    libraries. The problem I found is this:

    warning: cannot find entry symbol _start; defaulting to 000877e0

    Can anyone suggest why this might be occurring? OR give me some
    pointers to some useful information on the topic of static link for
    C++?

    Thanks,
    DS.
    , Jan 6, 2005
    #1
    1. Advertising

  2. Mike Hewson Guest

    wrote:
    > I want to link the C++ standard libraries statically


    I thought they were! If static here means "does not change while the
    program is executing", as opposed to dynamic ( Microsoft dll's et al ).

    --

    Cheers
    --
    Hewson::Mike
    "This letter is longer than usual because I lack the time to make it
    shorter" - Blaise Pascal
    Mike Hewson, Jan 6, 2005
    #2
    1. Advertising

  3. wrote:
    > I want to link the C++ standard libraries statically for my

    application
    > because I don't space for the .so files on my target platform.


    That's an interesting assessment: you don't have space for the shared
    object but you expect to have space for the application with the
    moral equivalent being linked in? I'd consider this to be relatively
    unlikely: this only works if you don't use major parts of the standard
    library (neither explicitly nor implicitly by other stuff you use).

    > After quite a bit of searching, I found very little information that
    > was helpful. The best information I found was at this link
    > http://fresco.org/~njs/c -without-stdc
    >
    > I followed the approach here and used -nostdlib to disable the

    default
    > linking. Instead I use the options:
    >
    > -lsupc++ -lgcc -lgcc_eh -lc -lgcc -lgcc_eh


    Of course, this whole gcc stuff is environment specific and off-topic
    in comp.lang.c++ and probably also in most of the other forums...
    However: why don't you use the option "-static"? This links the
    standard
    library statically as long as you have a static version thereof. Use of
    -nostdlib is more intended to people using a different implementation
    of
    the standard C++ library and is typically a little bit more involved
    than just that...

    > warning: cannot find entry symbol _start; defaulting to 000877e0


    I think this symbol and a few others you'll need are defined in crt1.o,
    crti.o, and crtn.o. Why these symbols are not included when specifying
    the option -nostdlib, I don't know.
    --
    <mailto:> <http://www.dietmar-kuehl.de/>
    <http://www.contendix.com> - Software Development & Consulting
    Dietmar Kuehl, Jan 6, 2005
    #3
  4. GTO Guest

    I am reading your post via comp.lang.c++.

    You forgot to add gnu.gcc.help to your cross-posting. The right choice of
    group is half the answer. The audience of gnu.gcc.help should be of more
    help.

    BTW, buy yourself a copy of Kurt Wall and William von Hagen's The Definitive
    Guide to GCC, Apress, 2004.

    Gregor

    PS: Did you try -static?

    <> wrote in message
    news:...
    >
    > I want to link the C++ standard libraries statically for my application
    > because I don't space for the .so files on my target platform.
    >
    > After quite a bit of searching, I found very little information that
    > was helpful. The best information I found was at this link
    > http://fresco.org/~njs/c -without-stdc
    >
    > I followed the approach here and used -nostdlib to disable the default
    > linking. Instead I use the options:
    >
    > -lsupc++ -lgcc -lgcc_eh -lc -lgcc -lgcc_eh
    >
    > where -lgcc -lgcc_eh has to be repeated twice for some reason.
    >
    > In summary the linker options I used are
    >
    > -Wl,-Bstatic -lsupc++ -lgcc -lgcc_eh -lc -lgcc -lgcc_eh
    >
    > followed by -Wl,-Bdynamic to link dynamically with some other
    > libraries. The problem I found is this:
    >
    > warning: cannot find entry symbol _start; defaulting to 000877e0
    >
    > Can anyone suggest why this might be occurring? OR give me some
    > pointers to some useful information on the topic of static link for
    > C++?
    >
    > Thanks,
    > DS.
    >
    GTO, Jan 7, 2005
    #4
  5. ucapajr

    Joined:
    May 3, 2008
    Messages:
    1
    C++ without stdc++

    AFIK:

    g++ includes stdc++ library by default as well as all the other C++ libraries that are required and the "base" gcc libraries etc to build the program.

    If you turn off the stdlibs with -nostdlib you need to know exactly what all the reqiured libs that g++ was implicitly including to get a c++ program to compile.

    As these libraries seem to be split into camps: gcc related ones and c++ related ones the problem of finding all the included required libraries to compile with g++ -nostdlib can be halved: use gcc to link and then just find out which c++ libraries are required!

    E.g

    g++ -I. -c main.cpp

    to compile the program to object using g++, then

    gcc main.o -lsupc++

    to obtain the executable. As you can see the only c++ required apart from stdc++ seems to be libsupc++. LDD analysis of the created program seems to indicate that this library is statically linked in.


    Cheers,

    ANdy
    ucapajr, May 3, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Herr Fieldmarshall

    Linking with Static Libraries (linux)

    Herr Fieldmarshall, Jan 28, 2005, in forum: C++
    Replies:
    4
    Views:
    1,091
    Lionel B
    Jan 28, 2005
  2. Replies:
    2
    Views:
    6,481
    Maett
    May 16, 2005
  3. barcaroller
    Replies:
    1
    Views:
    295
    Ian Collins
    Jun 12, 2007
  4. Replies:
    6
    Views:
    1,346
    James Kanze
    Jan 27, 2008
  5. Replies:
    1
    Views:
    146
    Terry Reedy
    Mar 8, 2013
Loading...

Share This Page