[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AC_FUNC_FORK doesn't work in C++ mode
From: |
Bruno Haible |
Subject: |
AC_FUNC_FORK doesn't work in C++ mode |
Date: |
Mon, 8 Nov 2004 14:14:02 +0100 |
User-agent: |
KMail/1.5 |
Hi,
On a glibc system, with CC=g++, AC_FUNC_FORK fails to define
HAVE_WORKING_FORK, due to bugs in the autoconf macro.
Test case:
$ cat configure.ac
AC_INIT(dummy,0)
AC_CONFIG_HEADERS(config.h)
AC_PROG_CC
AC_FUNC_FORK
AC_OUTPUT
$ autoconf
$ autoheader
$ CC=gcc ./configure
...
checking for fork... yes
checking for vfork... yes
checking for working fork... yes
checking for working vfork... (cached) yes
configure: creating ./config.status
config.status: creating config.h
$ grep WORKING config.h
#define HAVE_WORKING_FORK 1
#define HAVE_WORKING_VFORK 1
$ CC=g++ ./configure
...
checking for fork... yes
checking for vfork... yes
checking for working fork... no
checking for working vfork... (cached) yes
configure: creating ./config.status
config.status: creating config.h
$ grep WORKING config.h
/* #undef HAVE_WORKING_FORK */
#define HAVE_WORKING_VFORK 1
Now looking at the config.log we see that it contains:
configure:3045: checking for working fork
configure:3068: g++ -o conftest -g -O2 conftest.c >&5
conftest.c: In function `int main()':
conftest.c:9: error: `fork' undeclared (first use this function)
conftest.c:9: error: (Each undeclared identifier is reported only once for each
function it appears in.)
conftest.c:10: error: `exit' undeclared (first use this function)
configure:3071: $? = 1
configure: program exited with status 1
configure: failed program was:
| /* By Ruediger Kuhlmann. */
| #include <sys/types.h>
| #if HAVE_UNISTD_H
| # include <unistd.h>
| #endif
| /* Some systems only have a dummy stub for fork() */
| int main ()
| {
| if (fork() < 0)
| exit (1);
| exit (0);
| }
configure:3090: result: no
Here is a fix. It causes HAVE_UNISTD_H to be defined and exit() to be declared
in the prologue of the test program.
2004-11-07 Bruno Haible <address@hidden>
* lib/autoconf/functions.m4 (_AC_FUNC_FORK): Use AC_LANG_PROGRAM, to
make it work in C++ mode.
*** lib/autoconf/functions.m4.bak 2003-10-27 12:13:42.000000000 +0100
--- lib/autoconf/functions.m4 2004-11-07 15:07:27.000000000 +0100
***************
*** 1742,1759 ****
# -------------
AC_DEFUN([_AC_FUNC_FORK],
[AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
! [AC_RUN_IFELSE([/* By Ruediger Kuhlmann. */
! #include <sys/types.h>
! #if HAVE_UNISTD_H
! # include <unistd.h>
! #endif
! /* Some systems only have a dummy stub for fork() */
! int main ()
! {
! if (fork() < 0)
! exit (1);
! exit (0);
! }],
[ac_cv_func_fork_works=yes],
[ac_cv_func_fork_works=no],
[ac_cv_func_fork_works=cross])])]
--- 1742,1757 ----
# -------------
AC_DEFUN([_AC_FUNC_FORK],
[AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
! [AC_RUN_IFELSE([AC_LANG_PROGRAM([/* By Ruediger Kuhlmann. */
! #include <sys/types.h>
! #if HAVE_UNISTD_H
! # include <unistd.h>
! #endif
! ], [/* Some systems only have a dummy stub for fork() */
! if (fork() < 0)
! exit (1);
! exit (0);
! ])],
[ac_cv_func_fork_works=yes],
[ac_cv_func_fork_works=no],
[ac_cv_func_fork_works=cross])])]
- AC_FUNC_FORK doesn't work in C++ mode,
Bruno Haible <=