如何让Autotools将.r文件识别为C头文件而非Ratfor源文件?
Got it, let's tackle this issue head-on. The core problem here is that Autotools has a default rule where .r files get flagged as Ratfor source code (a vintage Fortran preprocessing language)—that's why it's panicking about needing an F77 compiler, even though your .r files are just C headers for information hiding. Here are two solid ways to fix this:
Method 1: Disable Ratfor Detection in configure.ac
Autoconf uses an internal macro _AC_F77_RATFOR to handle Ratfor file associations. We can explicitly block this macro to break that default link:
- Open your
configure.acfile in a text editor. - Add this line somewhere after
AC_INITand before any Fortran-related checks (like if you hadAC_PROG_F77defined):# Prevent Autoconf from treating .r files as Ratfor source m4_pattern_forbid([_AC_F77_RATFOR]) - Save the file, then re-run
autoreconf -iv. This tells Autotools to completely ignore the Ratfor association, so it won't hunt for an F77 compiler anymore.
Method 2: Explicitly Mark .r Files as C Headers in Makefile.am
If you want to leave no room for ambiguity, you can directly tell Automake that these .r files are headers (not code to compile):
- Open your
Makefile.amfile. - Add a line to include all
.rfiles in your project's header list:
If you only have specific# Treat .r files as C headers for information hiding HEADERS += $(wildcard *.r).rfiles, list them directly instead of usingwildcard, e.g.:HEADERS += object.r container.r - This signals to Automake that these files are meant to be included via
#include "file.r"in your C code, so it won't attempt to compile them with a Fortran toolchain.
Either method should resolve the error. If you want to be extra thorough, you can use both together—they don't conflict at all.
内容的提问来源于stack exchange,提问作者guus

