automake
[Top][All Lists]
Advanced

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

Re: Linking in C++ mode


From: Ralf Corsepius
Subject: Re: Linking in C++ mode
Date: 10 Nov 2002 13:01:08 +0100

Am Son, 2002-11-10 um 12.01 schrieb Earnie Boyd:
> John Levon wrote:
> > We have a C program which links to a C++ library, and we need to
> > tell automake to do the link in C++ mode  to avoid undefined references
> > to the C++ standard library. How can we do it ?
> > 
> > The Makefile.am looks as follows :
> > 
> > ---snip---
> > dist_sources = oprofiled.c opd_stats.c opd_kernel.c opd_image.c 
> > opd_sample_files.c \
> >         opd_image.h opd_printf.h opd_stats.h opd_kernel.h 
> > opd_sample_files.h p_module.h
> >  
> > EXTRA_DIST = $(dist_sources)
> >  
> > if kernel_support
> >  
> > AM_CPPFLAGS=-I ${top_srcdir}/libabi -I ${top_srcdir}/libutil -I 
> > ${top_srcdir}/libop -I ${top_srcdir}/libdb
> >  
> > bin_PROGRAMS = oprofiled
> >  
> > oprofiled_SOURCES = $(dist_sources)
> >  
> > if enable_abi
> > oprofiled_LDADD = ../libabi/libabi.a ../libdb/libdb.a ../libop/libop.a 
> > ../libutil/libutil.a
> > else
> > oprofiled_LDADD = ../libdb/libdb.a ../libop/libop.a ../libutil/libutil.a
> > endif
> >  
> > endif
> > ---snip---
> > 
> > libabi is the C++ library. It would be good to have a solution that
> > works for automake 1.5 upwards ...
> > 
> 
> You could always just add -lstdc++ to the oprofiled_LDADD variable.
This would be a fault, IMO.

The problem is trying to link a c-program against a c++-library. This
doesn't work in general, esp. not with g++, unless such a c++ library is
specially designed for such purposes. Unresolved references to libstdc++
indicate that your library has not been prepared for this.

A proper solution would be to use g++ to link the application. To
achieve this with automake, the easiest way is to convert the
main-application file to c++. In your case, renaming oprofiled.c to
oprofiled.cc would be sufficient.

Ralf






reply via email to

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