gnu linker and static/dynamic mix

Robert Kerr <>
10 May 2000 02:52:24 -0400

          From comp.compilers

Related articles
gnu linker and static/dynamic mix (Robert Kerr) (2000-05-10)
Re: gnu linker and static/dynamic mix (Arthur H. Gold) (2000-05-12)
| List of all articles for this month |

From: Robert Kerr <>
Newsgroups: comp.compilers
Date: 10 May 2000 02:52:24 -0400
Organization: Sandia National Laboratories, Albuquerque, NM USA
Keywords: linker, question

I'm having a problem with the gnu linker. Here's my situation: I'm
compiling on linux, using g++ (egcs 2.91.66) and letting it call ld
(2.9.1). I need to link with all static libraries, with one
exception. That exception is a set of commercial libraries that I
only have dynamic versions of.

If I needed all static, I'd just add -static to the g++ flags, and
everything would be hunky-dory. But, when I do that, the linker
complains about not finding the static versions of the commercial
libraries. So, I thought "Why don't I use the -static flag to g++,
then surround my commercial libraries with -Wl,-Bdynamic and
-Wl,-Bstatic?" Well, I did that, and the linker finished much too
rapidly (the fully-dynamic linked executable is about 55 MB, the
partially dynamic one from the above method is only about 16 MB) and
it doesn't execute correctly. When I try to run it it acts as if it
isn't there (I get the (No such file or directory) error message).

So, I tried adding -Wl,-aarchive to the link flags, then doing the
-Bdynamic,-Bstatic pair around the dynamic libraries. It links too
fast, and then when I try to run it I get a segfault. Running ldd on
this executable shows that it's still linking dynamically to libm,
libc, and libstdc++2.8.0.

So, am I approaching this wrong? Is there some reason this isn't
working for me? Thanks for any advice you might have.
Four hours of sleep a day is plenty.. you can make up for it at night.
* Robert Kerr, The morphing guy. * MS 0847 Sandia National Labs *
* * Albuquerque NM 87185-0847 *
* * Phone: (505) 844-8606 *
* * Fax: (505) 844-9297 *

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.