[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lib inclusion

> From: John Bindby <john.bindby@xxxxxxx.se>
> Date: Fri, 26 Apr 2002 09:32:13 +0200

> Take a really simple C++ program like:
> int main()
> {
>   vector<string> vStr;
>   string sTmp = "blaha";
>   vStr.push_back( sTmp );
>   return 0;
> }
> With simple compilation like:
> g++ -o stl_plain stl.cc
> g++ -static -o stl_static stl.cc
> g++ -Wl,-Bstatic,-lm,-Bdynamic -o stl_mixed stl.cc

Good, you're getting the same result with host gcc and g++ as
with gcc-cris. ;-)

Anyway, when playing games with static vs. dynamic linking and
the core C++ libraries libstdc++ and libm, you need to link
using gcc, since g++ links libstdc++ and libm dynamically by
itself.  See the command line sent to the linker, by using the
gcc and g++ option "-v".  For the example above (trimmed to
actually compile), I got rid of libm and libstdc++ as dynamic
references by:

g++ -c stl.cc
gcc -o stl_mixed stl.o -Wl,-Bstatic,-lstdc++,-lm,-Bdynamic

(Note that library files must generally be specified *after* all
program objects.)

You have to link both libm and libstdc++ statically (not just
libm), since libstdc++.so is dynamically linked to libm.so.

Hope this helps.

brgds, H-P