[GRASS-dev] configuration X fails with strict gcc flags

Hi,

I have a new laptop with Mandriva 2007.1 (so x.org). X is not
recognised although all header files are apparently there.
I debugged a bit and found the following (conftest.c and confdefs.h
manually extracted from configure):

cat conftest.c
#line 4672 "configure"
#include "confdefs.h"
#include <X11/Intrinsic.h>

int main() {
XtMalloc()
; return 0; }

cat confdefs.h

#define PEEK_XCLOSEIM 1
#define HAVE_LIMITS_H 1
#define HAVE_TERMIO_H 1
#define HAVE_TERMIOS_H 1
#define HAVE_UNISTD_H 1
#define HAVE_VALUES_H 1
#define HAVE_SYS_IOCTL_H 1
#define HAVE_SYS_MTIO_H 1
#define HAVE_SYS_RESOURCE_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TIMEB_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_UTSNAME_H 1
#define HAVE_LIBINTL_H 1
#define HAVE_ICONV_H 1
#define HAVE_LANGINFO_H 1
#define TIME_WITH_SYS_TIME 1
#define RETSIGTYPE void
#define HAVE_FTIME 1
#define HAVE_GETHOSTNAME 1
#define HAVE_GETTIMEOFDAY 1
#define HAVE_LSEEK 1
#define HAVE_NICE 1
#define HAVE_TIME 1
#define HAVE_UNAME 1
#define HAVE_SETEUID 1
#define HAVE_SETPRIORITY 1
#define HAVE_SETREUID 1
#define HAVE_DRAND48 1
#define HAVE_PUTENV 1
#define HAVE_SETENV 1
#define HAVE_NANOSLEEP 1
#define SETPGRP_VOID 1

gcc -o conftest -g -Wall -Werror-implicit-function-declaration -fno-common -mtune=nocona -m64 -minline-all-stringops -Wl,--export-dynamic -L/usr/lib64 conftest.c -lXt
configure: In function 'main':
configure:4676: error: too few arguments to function 'XtMalloc'

I think that -Werror-implicit-function-declaration is the problem here,
taking it out helps. But: For years I am using
  -Wall -Werror-implicit-function-declaration -fno-common
as flags for gcc to catch potential errors.

How to work around? Do we need to modify the XtMalloc() test?

grep XtMalloc /usr/include/X11/Intrinsic.h
extern char *XtMalloc(
extern char *_XtMalloc( /* implementation-private */
#define XtMalloc(size) _XtMalloc(size, __FILE__, __LINE__)
#define XtNew(type) ((type *) XtMalloc((unsigned) sizeof(type)))
    ((str) != NULL ? (strcpy(XtMalloc((unsigned)strlen(str) + 1), str)) : NULL)

thanks
Markus

Markus Neteler wrote:

I have a new laptop with Mandriva 2007.1 (so x.org). X is not
recognised although all header files are apparently there.
I debugged a bit and found the following (conftest.c and confdefs.h
manually extracted from configure):

cat conftest.c
#line 4672 "configure"
#include "confdefs.h"
#include <X11/Intrinsic.h>

int main() {
XtMalloc()
; return 0; }

gcc -o conftest -g -Wall -Werror-implicit-function-declaration -fno-common -mtune=nocona -m64 -minline-all-stringops -Wl,--export-dynamic -L/usr/lib64 conftest.c -lXt
configure: In function 'main':
configure:4676: error: too few arguments to function 'XtMalloc'

Odd; my config.log has:

  configure:4675: warning: implicit declaration of function `XtMalloc'

which implies that it isn't picking up the header. In fact, the
relevant portion of the configure script is:

  cat > conftest.$ac_ext <<EOF
  #line 4672 "configure"
  #include "confdefs.h"
  
  int main() {
  ${x_direct_test_function}()
  ; return 0; }
  EOF

which doesn't include any X headers.

Have you re-built your configure script using a different version of
autoconf?

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

Markus Neteler wrote:

I have a new laptop with Mandriva 2007.1 (so x.org). X is not
recognised although all header files are apparently there.
I debugged a bit and found the following (conftest.c and confdefs.h
manually extracted from configure):

cat conftest.c
#line 4672 "configure"
#include "confdefs.h"
#include <X11/Intrinsic.h>

int main() {
XtMalloc()
; return 0; }

gcc -o conftest -g -Wall -Werror-implicit-function-declaration
-fno-common -mtune=nocona -m64 -minline-all-stringops
-Wl,--export-dynamic -L/usr/lib64 conftest.c -lXt
configure: In function 'main':
configure:4676: error: too few arguments to function 'XtMalloc'

Odd; my config.log has:

  configure:4675: warning: implicit declaration of function `XtMalloc'

Mine, too. Sorry, had added a ine of debug output and forgot to mention.

configure:4510: checking for W11
configure:4538: checking for X
configure:4603: gcc -E conftest.c >/dev/null 2>conftest.out
configure:4679: gcc -o conftest -g -Wall
-Werror-implicit-function-declaration -fno-common -mtune=nocona -m64
-minline-all-stringops -Wl,--export-dynamic -L/usr/lib64 conftest.c -lXt
1>&5
configure: In function 'main':
configure:4675: error: implicit declaration of function 'XtMalloc'
configure: failed program was:
#line 4672 "configure"
#include "confdefs.h"

int main() {
XtMalloc()
; return 0; }
configure:5346: checking whether to use Curses

which implies that it isn't picking up the header. In fact, the
relevant portion of the configure script is:

  cat > conftest.$ac_ext <<EOF
  #line 4672 "configure"
  #include "confdefs.h"
  
  int main() {
  ${x_direct_test_function}()
  ; return 0; }
  EOF

which doesn't include any X headers.

Have you re-built your configure script using a different version of
autoconf?

Probably I added it in the debug output since I assumed that it was
there. So, after reset to CVS version, it turns out to be this problem:

configure:4675: error: implicit declaration of function 'XtMalloc'

probably still caused by the -Werror-implicit-function-declaration
flag. Maybe the gcc behaviour changed? It is
Target: x86_64-mandriva-linux-gnu
gcc version 4.1.2 20070302 (prerelease) (4.1.2-1mdv2007.1)

On my office box (RHEL4, 64bit), it works with identical flags, but it is:
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)

I wonder why only this test fails.

Markus
--
View this message in context: http://www.nabble.com/configuration-X-fails-with-strict-gcc-flags-tf4062146.html#a11554206
Sent from the Grass - Dev mailing list archive at Nabble.com.

Markus Neteler wrote:

> Have you re-built your configure script using a different version of
> autoconf?

Probably I added it in the debug output since I assumed that it was
there. So, after reset to CVS version, it turns out to be this problem:

configure:4675: error: implicit declaration of function 'XtMalloc'

probably still caused by the -Werror-implicit-function-declaration
flag.

Yes. You may need to add that flag manually to Platform.make after
configure has run.

The autoconf linking checks (AC_CHECK_FUNCS, AC_CHECK_LIB etc) never
include the header files, as that would give "too few arguments"
errors, like the one you encountered (configure only knows the name of
the function, not its type, so it has to call it without arguments).

Maybe the gcc behaviour changed? It is
Target: x86_64-mandriva-linux-gnu
gcc version 4.1.2 20070302 (prerelease) (4.1.2-1mdv2007.1)

On my office box (RHEL4, 64bit), it works with identical flags, but it is:
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)

I wonder why only this test fails.

The test program created by AC_CHECK_FUNC[S] normally includes a dummy
prototype for the function, e.g.:

  #line 4893 "configure"
  #include "confdefs.h"
  /* Override any gcc2 internal prototype to avoid an error. */
  /* We use char because int might match the return type of a gcc2
      builtin and then its argument prototype would still apply. */
===> char dnet_ntoa();
  
  int main() {
  dnet_ntoa()
  ; return 0; }

However, the X checks call AC_TRY_LINK directly, without providing a
prototype. I don't know why, and I don't know why this didn't trigger
an error before.

The XtMalloc check is part of AC_PATH_X, and calling that isn't really
optional if we want to use X.

--
Glynn Clements <glynn@gclements.plus.com>