Compiling code with gcc on macOS Monterey 12.5.1 results in clang error

Viewed 143

I am compiling C++, Fortran, and OpenMPI code using Homebrew installed packages. I also use the make (GNU Make 4.3) and cmake (3.24.1) packages installed with Homebrew. I compile the test programs as follows:

### C++ ###
int main (int argc, char** argv)
{
    int x=2;
    return 0;
}

$ g++ test.cc
> clang: error: invalid version number in '-mmacosx-version-min=12.5'

### Fortran ###
program hello
        print *, "Hello, world!"
end program hello

$ gfortran test.f90
> clang: error: invalid version number in '-mmacosx-version-min=12.5'

I get a clang error: clang: error: invalid version number in '-mmacosx-version-min=12.5' when using gcc-12 and gfortran-12. The version number requirement in the above error changes depending on the gcc version installed. For example, gcc-10 and gcc-11 result in clang: error: invalid version number in '-mmacosx-version-min=12.0'. What's interesting is that the error invoked is coming from Apple clang even though I am not using it for compiling any of the programs.

Some relevant specs:

  • macOS Monterey 12.5.1
  • xcode-select version 2395
  • xcode-select path: /Library/Developer/CommandLineTools
$ /usr/bin/clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Update: I now installed gfortran using the intel standalone installer here, I still get the same error.

1 Answers

Someone who seem to have had the same problem:

Found solution: reinstalling the Command Line Tools and exporting SYSTEM_VERSION_COMPAT=1 worked for me. Another possible solution could be to force the compilation to occur through GCC only, but this is not something I tried.

note: compilation was performed without including MPI software.

note2: pkg-config had to be installed as an extra dependency, but this was probably required by CMake.

https://groups.google.com/g/hande-user/c/dtGvyFTJFWE

Related