mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.47k stars 1.58k forks source link

compiler.find_library() always fails with a Fortran compiler and prefer_static=true #12757

Open svillemot opened 7 months ago

svillemot commented 7 months ago

Consider the following minimal meson.build:

project('mesontest', 'fortran')
fortran_compiler = meson.get_compiler('fortran')
dep = fortran_compiler.find_library('blas')

(where blas can be replaced by any library with both a static .a and a dynamic .so version)

If one tries to setup the project with prefer_static=true:

meson setup -Dprefer_static=true builddir

Then it fails because meson feeds C code (instead of Fortran code) to the Fortran compiler. Here is the excerpt from meson-log.txt:

-----------
Command line: `gfortran /tmp/meson-bug/builddir/meson-private/tmp83zyjls8/testfile.f90 -o /tmp/meson-bug/builddir/meson-private/tmp83zyjls8/output.exe -D_FILE_OFFSET_BITS=64 -O0` -> 1
stderr:
/tmp/meson-bug/builddir/meson-private/tmp83zyjls8/testfile.f90:2:10:

    2 |         #include<stddef.h>
      |          1
Error: Invalid character in name at (1)
/tmp/meson-bug/builddir/meson-private/tmp83zyjls8/testfile.f90:3:10:

    3 |         #include<stdio.h>
      |          1
Error: Invalid character in name at (1)
/tmp/meson-bug/builddir/meson-private/tmp83zyjls8/testfile.f90:6:19:

    6 |             return 0;
      |                   1
Error: Alternate RETURN statement at (1) is only allowed within a SUBROUTINE
/tmp/meson-bug/builddir/meson-private/tmp83zyjls8/testfile.f90:7:9:

    7 |         }
      |         1
Error: Invalid character in name at (1)
-----------
Could not compile test file /tmp/meson-bug/builddir/meson-private/tmp83zyjls8/testfile.f90: 1

The problem does not manifest with -Dprefer_static=false.

Tested with meson 1.3.1-1 from Debian unstable amd64.

svillemot commented 7 months ago

The problem seems to come from method _find_library_real of class CLikeCompiler (from which the class FortranCompiler is derived). That method calls method output_is_64bit, which only works with C and C++ compilers (because it generates C code for testing).

dcbaker commented 7 months ago

Yup, looks like no one ever implemented the sizeof, cross_sizeof, or output_is_64bit checks for Fortran. Neither of these look super hard to fix if you know Fortran (I don't), since it should be as simple as copying the CLike implementations, and replacing the C code with Fortran code. I'd be happy to review patches if someone wrote them