[Top][All Lists]

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

Re: linking against c++ shared library built using autoconf (and libtool

From: Ralf Corsepius
Subject: Re: linking against c++ shared library built using autoconf (and libtool)
Date: Thu, 15 Jul 2004 16:00:43 +0200

On Thu, 2004-07-15 at 15:14, Ludovic Courtès wrote:
> Today, 12 minutes, 50 seconds ago, Ralf Corsepius wrote:
> > This way you compile your whole program using the C++ compiler, i.e. you
> > actually are compiling it as a C++ program, not as a c-program.
> Right.  But it doesn't hurt much (wrt. mangled symbol names, for
> instance) so long as you are compiling a program, not a library.
You are treating your code as c++, not as c-code.

> [...]
> > This only works with some (old) versions of gcc for some selected
> > targets (eg. gcc-2.9x on i386). In general (esp. with gcc >= 3.0), it
> > does not work.
> G++ 3.0.2 on i386 has `libstdc++' too.  From my understanding of
> (especially 5.2),
> `libstdc++' won't disappear from G++.  Were you talking about `libg++'?
No, I am referring to libstdc++. libstdc++ is an internal implementation
detail of g++ you should not have to care about.

However "presence of libstdc++" is not the actual problem, here. The
actual problem is "using g++ to link" means more than adding "-lstdc++"
to LDFLAGS. For example, on some targets w/ some gcc-versions it means
adding further libs (e.g. libsupc++), composing ctors/dtors,  pulling in
alternative startup code etc.

What it actually does highly depends on the gcc-version you are using
and the target (architecture, OS, object format etc.) you are compiling

> > >  but other C++
> > > environments do not necessarily have `libstdc++').  In order to link
> > > against a C++ library without having a C++ compiler, one needs to have
> > > `libstdc++' (or equivalent) statically linked into the C++ library.
> > Sorry, this is not true.
> > 
> > With g++, in general, you have to use "g++" to link and must not
> > explicitly add "-lstdc++". Admitted, there exist some occasions for some
> > apps/libs on some architectures for some versions of gcc where the trick
> > you describe sometimes work, but in general, this does not work.
> Yes, that's what I meant.  However, one has to consider that the user
> linking against your library doesn't necessarily have a C++ compiler and
> runtime environment (think of a library implemented in C++ which
> provides a plain C API).  How would you accommodate such a situation if
> not by linking the C++ lib against libstdc++.a or equivalent?
This would be very hard. You'd have to design your  library in such a
way that it does not have any unresolved C++ symbol.

In practice, this would mean to avoid  using the STL and to avoid most
features that make C++ attractive (no static constructors, no iostreams
etc.). Furthermore, you'd have to set up your CXX-flags in such a way
that it does not generate C++ symbols (type-info, exceptions).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]