AC_LINK_IFELSE unexpectedly fails on Ubuntu 12.04

2013-10-25 Thread David Pointon
Hi ,

When running the configure script for OpenJDK on Ubuntu 12.04, the 
'checking if we can compile and link with freetype...' check fails 
unexpectedly ...

$ sh ./configure --with-jdk-variant=ibm 
--with-import-hotspot=../../SVN/sdk80 --enable-openjdk-only 
--with-freetype-lib=/usr/lib/i386-linux-gnu 
--with-freetype-include=/usr/include
.
.
configure: Found freetype include files at /usr/include using 
--with-freetype
checking for freetype includes... /usr/include
checking for freetype libraries... /usr/lib/i386-linux-gnu
checking if we can compile and link with freetype... no
configure: Could not compile and link with freetype. This might be a 
32/64-bit mismatch.
configure: Using FREETYPE_CFLAGS=-I/usr/include/freetype2 -I/usr/include 
and FREETYPE_LIBS=-L/usr/lib/i386-linux-gnu -lfreetype
configure: error: Can not continue without freetype. 
configure exiting with result code 1
$

The above confirms that the freetype headers have, but interestingly not 
the libraries have not, been found. Inspection of the build log reveals 
the following command to have been run:

configure:34201:  /usr/bin/g++-4.6 -o conftest -I/usr/include/freetype2 
-I/usr/include -L/usr/lib/i386-linux-gnu -lfreetype conftest.cpp 5

against the conftest code. The problem can be readily simplified viz - 
given a copy of the conftest file, in t.c, containing ...

$ cat t.c
#includeft2build.h
#include FT_FREETYPE_H
int main () {
FT_Init_FreeType(NULL);
return 0;
}
$

... the following commands and their results are all observed ...

$ compiler t.c `freetype-config --cflags` `freetype-config --libs`
$ compiler `freetype-config --cflags` t.c `freetype-config --libs`
$ compiler `freetype-config --cflags` `freetype-config --libs` t.c
/tmp/ccCTZzpt.o: In function `main':
t.c:(.text+0x11): undefined reference to `FT_Init_FreeType'
collect2: ld returned 1 exit status
$

where the same results are observed whether compileris cc, gcc or g++.

Thus it will be seen that, unlike the gcc of old, the ordering of the 
options to the compiler is of paramount importance on Ubuntu - the linker 
option(s) must be specified after the source source file and any CFLAGS.

I have repeated the exercise on Solaris 10, AIX 7.1  RHEL 6 - on none of 
which is the problem prevalent i.e. the command line options can be 
specified in any order resulting in a.out being successfully generated.

As configure failed, running make check is not possible since there is no 
Makefile.

Rgds ,

--
Dave Pointon FIAP MBCS | Now I saw, tho' too late, the folly of beginning 
a work before we
Test/Software Engineer |  count the cost and before we we judge 
rightly of our strength to
  |  go thro' with it - Robinson 
Crusoe
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU




Re: AC_LINK_IFELSE unexpectedly fails on Ubuntu 12.04

2013-10-25 Thread David Pointon
Hiya Paul ,

AFAICT, the problem stems from a generated shell function called 
ac_fn_cxx_try_link but there's no trace of that in any of the OJDK scripts 
other than in generated-configure.sh - for which there's no provenance, 
hence I inferred that it came from within autoconf ... but of course, I 
could be wrong ;-/

Rgds ,

--
Dave Pointon FIAP MBCS | Now I saw, tho' too late, the folly of beginning 
a work before we
Test/Software Engineer |  count the cost and before we we judge 
rightly of our strength to
  |  go thro' with it - Robinson 
Crusoe



From:   Paul Eggert egg...@cs.ucla.edu
To: David Pointon/UK/Contr/IBM@IBMGB, bug-autoconf@gnu.org, 
Cc: david.poin...@unix.net
Date:   25/10/2013 15:46
Subject:Re: AC_LINK_IFELSE unexpectedly fails on Ubuntu 12.04



This would appear to be a problem in OpenJDK's configure.ac
file, not in Autoconf itself, no?  So you should send a bug
report to the OpenJDK folks.



Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU




Re: AC_LINK_IFELSE unexpectedly fails on Ubuntu 12.04

2013-10-25 Thread Paul Eggert
David Pointon wrote:
 AFAICT, the problem stems from a generated shell function called 
 ac_fn_cxx_try_link

Sure, but that function depends on the appropriate -L, -I, -l, etc.
options being set appropriately for your system, and if those options
are messed up than that function won't work.  It appears that the
options are messed up somehow.  Most likely it's OpenJDK since
we aren't observing the problem with other packages that use
Autoconf.  It's of course possible that it is an Autoconf bug
but we'll need someone to debug the script in question to determine
that, and most likely that'll have to be someone with OpenJDK
build expertise.



Re: AC_LINK_IFELSE unexpectedly fails on Ubuntu 12.04

2013-10-25 Thread Russ Allbery
David Pointon dpoin...@uk.ibm.com writes:

 The above confirms that the freetype headers have, but interestingly not 
 the libraries have not, been found. Inspection of the build log reveals 
 the following command to have been run:

 configure:34201:  /usr/bin/g++-4.6 -o conftest -I/usr/include/freetype2 
 -I/usr/include -L/usr/lib/i386-linux-gnu -lfreetype conftest.cpp 5

The contents of $FREETYPE_LIBS are being put on the compilation command
line before the program to be compiled instead of afterwards.  This has
never been guaranteed to work.  Some linkers dynamically reorder the link
line and cause this to work, but you can't rely on that behavior, and it
stopped working in the versions of the toolchain currently in Ubuntu.

I suspect somewhere in the configure machinery for this package, something
is adding $FREETYPE_LIBS to $LDFLAGS.  This is wrong.  $LDFLAGS and $LIBS
are intentionally separate, and $LIBS flags cannot go into $LDFLAGS for
exactly this reason.

Compilers and linkers are generally more forgiving about the location of
the -L flags, so putting $LDFLAGS flags into $LIBS will usually work if
there's no way to get properly separated $LDFLAGS and $LIBS variables,
which may be the case here.

Short version: If I'm right, find where the configure script is throwing
$FREETYPE_LIBS into $LDFLAGS and change it to add those flags to $LIBS
instead.

-- 
Russ Allbery (r...@stanford.edu) http://www.eyrie.org/~eagle/