URL: <https://savannah.gnu.org/support/?110294>
Summary: AC_LANG_PUSH/AC_LANG_POP malfunction inside AC_DEFUN Project: Autoconf Submitted by: haible Submitted on: Tue 18 Aug 2020 06:38:28 PM CEST Category: None Priority: 5 - Normal Severity: 3 - Normal Status: None Privacy: Public Assigned to: None Originator Email: Open/Closed: Open Discussion Lock: Any Operating System: GNU/Linux _______________________________________________________ Details: With Autoconf 2.69, a wrong configure file is generated when the configure.ac file (attached) contains - an AC_DEFUN, - an AC_LANG_PUSH([C++]) / AC_LANG_POP([C++]) pair inside the AC_DEFUN, - no AC_LANG_CXX invocation (because my package has optional C++ support; invoking AC_LANG_CXX would make configure abort if no C++ compiler is found, which is not what I want). How to reproduce: 1. In an empty directory, save the attached configure.ac file. 2. aclocal 3. autoconf 4. touch install-sh 5. configure The output contains: checking for library needed for log()... checking whether the C++ compiler has <cuchar>... no checking for library needed for pow()... -lm So, autoconfiguration has correctly determined that use of pow() needs linking with -lm. But it has incorrectly determined that use of log() does not need linking with -lm. Why? The config.log shows it: configure:4398: checking for library needed for log() configure:4416: g++ -o conftest -g -O2 conftest.cpp >&5 configure:4416: $? = 0 ... configure:4480: checking for library needed for pow() configure:4498: gcc -o conftest -g -O2 conftest.c >&5 /tmp/ccYm3cJH.o: In function `main': /tmp/1/conftest.c:19: undefined reference to `log' collect2: error: ld returned 1 exit status configure:4498: $? = 1 You can see that it has executed the log() test with the C++ compiler! And since libstdc++ is linked with libm (use 'ldd' to confirm this), the "g++ -o conftest -g -O2 conftest.cpp" command succeeded. The configure script uses a variable 'ac_compile'. See where it is being set: $ grep -n '\(ac_compile=\|<math.h>\)' configure 1882:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 2498:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3281:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3287:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3339:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3695:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3719:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3870:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3991:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4012:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4263:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4406: #include <math.h> 4430:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4464:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4488: #include <math.h> You can clearly see that the last assignment to ac_compile before the first <math.h> test is in line 4263 and that it prepares for use of the C++ compiler, not of the C compiler. The bizarre thing is that when adding an invocation of AC_PROG_CXX (at one of the two places indicated by a comment "This fixes it!") makes the bug disappear. Then we see $ grep -n '\(ac_compile=\|<math.h>\)' configure 1882:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 2498:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3281:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3287:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3339:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3695:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3719:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3870:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 3991:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4008:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4259:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4406: #include <math.h> 4430:ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4464:ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' 4488: #include <math.h> Here the last assignment to ac_compile before the first <math.h> test activates the C compiler. This is good. But as I said above, I do not want to use AC_PROG_CXX. _______________________________________________________ File Attachments: ------------------------------------------------------- Date: Tue 18 Aug 2020 06:38:28 PM CEST Name: configure.ac Size: 3KiB By: haible <http://savannah.gnu.org/support/download.php?file_id=49686> _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/support/?110294> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/