cross compile and checking for C compiler default output file name

Josef Wolf
Thu Jan 14 13:20:00 GMT 2010


In newlib-1.15.0, the following hunk had been added to

 @@ -81,7 +43,29 @@
 +AC_MSG_CHECKING([target cpu family])
 +dnl Temporarily modify LDFLAGS so that link tests will succeed without
 +dnl a C library.  Note that we may not have a C librabry yet and that
 +dnl autoconf automatically adds script to check whether we can create
 +dnl an executable or not.
 +LDFLAGS="-nostdlib -e main"
 +AC_PREPROC_IFELSE([#ifndef __mcoldfire__
 +               #error we are not coldfire
 +               #endif],
 +              DO="cf",)
 +AC_PREPROC_IFELSE([#ifndef __mfido__
 +               #error we are not fido
 +               #endif],
 +              DO="fido",)

This causes the configure script to fail when building newlib for a cross
compiler, since cross compiler do _not_ create executables. Here's the
error message:

 configure:2336: checking for C compiler default output file name
 configure:2339: m68k-coff-gcc -B/var/tmp/builds/crossgcc/build/newlib/m68k-coff/m68000/newlib/ -isystem /var/tmp/builds/crossgcc/build/newlib/m68k-coff/m68000/newlib/targ-include -isystem /var/tmp/builds/crossgcc/src/newlib-1.15.0/newlib/libc/include  -m68000 -nostdlib -e main conftest.c  >&5
 /tmp/ccWpP6Cn.o(.text+0x6):conftest.c: undefined reference to `__main'
 collect2: ld returned 1 exit status
 configure:2342: $? = 1
 configure: failed program was:
 | /* confdefs.h.  */
 | #define PACKAGE_NAME ""
 | #define PACKAGE_TARNAME ""
 | #define PACKAGE_VERSION ""
 | #define PACKAGE_STRING ""
 | /* end confdefs.h.  */
 | int
 | main ()
 | {
 |   ;
 |   return 0;
 | }
 configure:2381: error: C compiler cannot create executables
 See `config.log' for more details.

This is detected wrong, since my (cross-) compiler _can_ create working
executables, at least with newslib-1.14.0.

Any hints how to work around this problem?

More information about the Newlib mailing list