467,879 Members | 1,331 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

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


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.

Jul 22 '05 #1
  • viewed: 9907
Share:
3 Replies
da***********@excite.com 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:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 22 '05 #2
da***********@excite.com 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
Jul 22 '05 #3
GTO
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?

<da***********@excite.com> wrote in message
news:11**********************@z14g2000cwz.googlegr 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.

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Grzegorz Dostatni | last post: by
3 posts views Thread by Rickard Lind | last post: by
15 posts views Thread by Notre Poubelle | last post: by
reply views Thread by abarun22 | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.