Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static linking of C++ libraries with gcc/g++

Reply
Thread Tools

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

 
 
daniel_shaw01@excite.com
Guest
Posts: n/a
 
      01-06-2005

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.

 
Reply With Quote
 
 
 
 
Mike Hewson
Guest
Posts: n/a
 
      01-06-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Dietmar Kuehl
Guest
Posts: n/a
 
      01-06-2005
(E-Mail Removed) 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.
--
<(E-Mail Removed)> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

 
Reply With Quote
 
GTO
Guest
Posts: n/a
 
      01-07-2005
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?

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> 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.
>



 
Reply With Quote
 
ucapajr ucapajr is offline
Junior Member
Join Date: May 2008
Posts: 1
 
      05-03-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking with static libraries for Python standard components such as OpenSSL gerson.kurz@gmail.com Python 1 03-08-2013 10:03 AM
C++ (g++) linker error linking dependent static libraries to createexecutable sriram.sundararajan@gmail.com C++ 6 01-27-2008 12:14 PM
[Potentially OT] Linking static and shared libraries... barcaroller C++ 1 06-11-2007 11:50 PM
how to link static library to another static libraries free2cric@yahoo.com C++ 2 05-16-2005 04:40 PM
Linking with Static Libraries (linux) Herr Fieldmarshall C++ 4 01-28-2005 02:14 PM



Advertisments