[Top][All Lists]

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

Re: automake links my C programs with the C++ compiler

From: Bruno Haible
Subject: Re: automake links my C programs with the C++ compiler
Date: Mon, 11 Sep 2006 16:53:10 +0200
User-agent: KMail/1.9.1


Is someone on this list capable of fixing this bug?

The automake doc says:

     You can override the linker on a per-program basis.  By default the
     linker is chosen according to the languages used by the program.
     For instance, a program that includes C++ source code would use
     the C++ compiler to link.

But what automake actually does is a worst-case estimation: it links
with the C++ compiler even if C++ source code is included in a FALSE

The fix should be to generate a libfoo_la_LINK variable. Assuming
libfoo_la_SOURCES was defined as follows:

libfoo_la_SOURCES =
if COND1
  libfoo_la_SOURCES += foo1.c
if COND2
  libfoo_la_SOURCES += foo2.upc
if COND3
  libfoo_la_SOURCES += foo3.m
if COND4
  libfoo_la_SOURCES += foo4.f
if COND5
  libfoo_la_SOURCES += foo5.cxx
if COND6
  libfoo_la_SOURCES += foo6.cc

The libfoo_la_LINK variable should be defined like this:

# First the fallback definition, linking with C:
libfoo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CCFLAGS) \
        $(CCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
# Then conditional overrides in the reverse order of the list in automake
# function resolve_linker.
# Conditional definition for UPCLINK:
@address@hidden = $(LIBTOOL) --tag=UPC $(AM_LIBTOOLFLAGS) \
# Conditional definition for OBJCLINK:
@address@hidden = $(LIBTOOL) --tag=OBJC $(AM_LIBTOOLFLAGS) \
# Conditional definition for F77LINK:
@address@hidden = $(LIBTOOL) --tag=F77 $(AM_LIBTOOLFLAGS) \
@COND4_TRUE@    $(LIBTOOLFLAGS) --mode=link $(F77LD) $(AM_FFLAGS) \
# Conditional definition for CXXLINK:
@address@hidden = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
@address@hidden = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \

I think the modifications needed for this output are
  - to change the linkers_used variable to contain a list of pairs
    (condition, linker variable) instead of just a single linker variable,
  - to not call resolve_linker,
  - to change the return value of handle_source_transform and the first
    argument of define_per_target_linker_variable to be such a list as well,
  - to rewrite define_per_target_linker_variable so that it emits definitions
    of libfoo_la_LINK in a loop, appropriately conditionalized, in order
    of increasing priority.


reply via email to

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