automake
[Top][All Lists]
Advanced

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

Re: C programs using C++ libraries


From: Bob Friesenhahn
Subject: Re: C programs using C++ libraries
Date: Tue, 9 Dec 2003 14:07:57 -0600 (CST)

On Tue, 9 Dec 2003, Billy Biggs wrote:

>   I have a C program that uses a library which internally uses C++, but
> exposes a C API.  I have a user who experiences linking problems about
> missing standard C++ stuff, fixed by using "g++" to link.  I am looking
> for help in understanding this and what the correct solution is.
>
>   This has been discussed before on this list [1] and solutions given.
> I could build a dummy.cc to force C++ linking, I could use my own
> program_LINK, or I could do some magic with setting CCLD or similar.
>
>   I have a few questions, please let me know if there is a better forum
> for them:
>
>   1. Why does my program need to be linked with a C++ compiler in some
>      cases and not in others?  Shared libraries should bring in their
>      own dependencies, or libtool should find them, no?  Is something
>      broken with how the library is built?

Operating system support varies regarding embedded dependency
information in shared libraries, so depending on that feature is not
portable.  Libtool would help handle library dependencies if the
problem library was linked using libtool, since then there would be a
.la file associated with the library which includes the known library
dependencies.

Besides library dependencies, C++ code may also have different program
intialization requirements (e.g. to support static construction,
destruction, and exceptions) so a different startup module (the code
that eventually invokes main()) may be supplied by the compiler.

>   2. I use libtool (but I do not understand why I use it).  Is the
>      following correct for my program_LINK command if I use libtool:
>
>      program_LINK = $(LIBTOOL) --mode=link $(CXX) $(AM_CFLAGS) $(CFLAGS) \
>         $(AM_LDFLAGS) $(LDFLAGS) -o $@

This seems to be from an Automake generated Makefile.  Are you using
Automake?  Passing the C++ compiler as the tool to use for linking
seems reasonable.

>   3. Who defines CXXLD and how?  I have seen this variable referenced,
>      it looks like I should use it above (to match CCLD), but nothing
>      seems to define it.  Is it obsolete?

I believe that this is a definition generated by the AC_PROG_LIBTOOL
autoconf macro.  If you are not including libtool with your package,
then this macro won't be defined.  If you are embedding libtool in
your package, then you should definitely include AC_PROG_LIBTOOL in
configure.ac.

>   Thanks for your help,
>   -Billy
>
>   [1] http://mail.gnu.org/archive/html/automake/2002-11/msg00046.html
>
>
>

======================================
Bob Friesenhahn
address@hidden
http://www.simplesystems.org/users/bfriesen





reply via email to

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