tags:

views:

501

answers:

2

Hello,

I want to use a different STL with g++ instead of its default libstdc++. What is the easiest way to do this?

I found -nostdinc++ flag which inhibits g++ from looking for its STL headers but this is only a compile time thing. It will still make g++ link against its own STL.

So I need to find a way to inhibit the linking.

Thanks!

+5  A: 

One easy method is to build with gcc rather than g++ - this won't link in the default C++ libraries, but will still compile .cpp files as C++ code. You will have to specify your alternative libraries explicitly on the command line.

anon
I see. Do I have to explicitly specify any other libraries (other than the STL) that g++ would otherwise have included but will be skipped now that I am using gcc? Thanks.
MK
There are also -nostdlib and -nodefaultlibs options. But they seems less usefull for the OP purpose and he would need to provide more support functions or explicitly link against libc. Note also that the g++ driver automatically provides -lm while gcc doesn't.
AProgrammer
gcc should still link in the necessary C libraries etc. though not the maths library as AProgrammer observes.
anon
A: 

You might try to use the STLport instead of the default gcc stl implementation. In my Ubuntu when I install the package there is a library for static linking (/usr/lib/libstlport.a). This is just a guessing I don't know if it will actually work.

fco.javier.sanz