autoconf
[Top][All Lists]
Advanced

[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 14:37:10 +0200

On Thu, 2004-07-15 at 09:34, Ludovic Courtès wrote:
> Hi,
> 
> Yesterday, 14 hours, 14 minutes, 58 seconds ago, Wil Turner wrote:
> > Looking over the output when the library is built, I notice that all of 
> > the link steps are done using gcc instead of g++, but I'm not sure 
> > where to change this in configure.ac; g++ *is* used for the .cc -> .o 
> > steps. Is there a variable that can be set to change the compiler used 
> > for these steps, or am I doing something else wrong? The documentation 
> > doesn't seem to mention this problem at all.
> 
> I personally use the following trick in the `Makefile.am' that actually
> links against a C++ library:
> 
>   CC = $(CXX)
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.

> AFAIK, this is the only portable way to link, eg. a C program against a
> C++ library
Well, with gcc/g++, one rather safe way is to use the C++ linker to link
the application (There exist other ways, which require low level
-Xlinker magic in your linker calls).

One way to persuade automake to doing this, is  adding a c++-file to the
application's sources (Automake uses the c++ linker, if it finds a file
using a c++-suffix in a *_PROGRAMS's *_SOURCES).

>  (using `cc -lstdc++' works with GNU C++
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.

>  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.

Ralf






reply via email to

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