Issue between CMake, MPI, macOS (XCode 16?) and gcc

All,

I don’t know if this is a CMake issue or not, but it seems to be? To wit, I have a boring MPI C Hello World code and it builds just fine using either gcc or clang on the command line. First gcc:

❯ mpicc --version
gcc-14 (Homebrew GCC 14.2.0) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

❯ mpicc ./hello-world.c
❯ mpirun -np 2 ./a.out
Hello world from processor gs6101-alderaan-198120226026.ndc.nasa.gov, rank 1 out of 2 processors
Hello world from processor gs6101-alderaan-198120226026.ndc.nasa.gov, rank 0 out of 2 processors

and clang:

❯ mpicc --version
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
❯ mpicc ./hello-world.c
❯ mpirun -np 2 ./a.out
Hello world from processor gs6101-alderaan-198120226026.ndc.nasa.gov, rank 0 out of 2 processors
Hello world from processor gs6101-alderaan-198120226026.ndc.nasa.gov, rank 1 out of 2 processors

Now I whip up a simple CMakeLists.txt and:

cmake_minimum_required(VERSION 3.20)
project(HelloWorldC)
find_package(MPI REQUIRED COMPONENTS C)
add_executable(hello_world hello-world.c)
target_link_libraries(hello_world PRIVATE MPI::MPI_C)

and then first we build with clang:

❯ cmake -B build-clang -S .
-- The C compiler identification is AppleClang 16.0.0.16000026
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found MPI_C: /Users/mathomp4/installed/Compiler/clang-gfortran-14/openmpi/5.0.5/lib/libmpi.dylib (found version "3.1")
-- Found MPI: TRUE (found version "3.1") found components: C
-- Configuring done (1.0s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/mathomp4/CMakeTutorial/hello-world-c/build-clang

Yay! Now with gcc:

❯ cmake -B build-gcc -S .
-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Users/mathomp4/.homebrew/brew/bin/gcc-14 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Users/mathomp4/.homebrew/brew/bin/g++-14 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find MPI_C (missing: MPI_C_WORKS)
CMake Error at /Users/mathomp4/.homebrew/brew/Cellar/cmake/3.30.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find MPI (missing: MPI_C_FOUND C)
Call Stack (most recent call first):
  /Users/mathomp4/.homebrew/brew/Cellar/cmake/3.30.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  /Users/mathomp4/.homebrew/brew/Cellar/cmake/3.30.3/share/cmake/Modules/FindMPI.cmake:1841 (find_package_handle_standard_args)
  CMakeLists.txt:3 (find_package)


-- Configuring incomplete, errors occurred!

Well huh.

I mean, my MPI stack does work, but for some reason not when CMake tries to detect it.

I note that this all started when I updated to XCode 16 and I see that @brad.king already has one XCode 16 issue, but this seems more…basic and boring.


I’m using CMake 3.30.3:

❯ cmake --version
cmake version 3.30.3

This happens sometimes when the Xcode update changes the meaning of compiler flags or deprecates flags. Since MPI is so complex, it is a canary that feels these issues first.

Look at file build-gcc/CMakeFiles/CMakeConfigureLog.yaml for clues re: MPI_C_WORKS.

Since Xcode 16 is brand new, I already see issues raised across several different projects unrelated to CMake or MPI etc.

Other Xcode major releases have required Openmpi itself to make updates to itself to be compatible. I don’t know yet as I haven’t looked at it yet.

Ahhh. You are the smart one. If I look in there, I see a lot of:

        In file included from /Users/mathomp4/CMakeTutorial/hello-world-c/build/CMakeFiles/CMakeScratch/TryCompile-T2e2Rg/test_mpi.c:6:
        /Users/mathomp4/.homebrew/brew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include-fixed/stdio.h:83:8: error: unknown type name 'FILE'
           83 | extern FILE *__stdinp;
              |        ^~~~
        /Users/mathomp4/.homebrew/brew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include-fixed/stdio.h:81:1: note: 'FILE' is defined in header '<stdio.h>'; this is probably fixable by ad
ding '#include <stdio.h>'
           80 | #include <sys/_types/_seek_set.h>
          +++ |+#include <stdio.h>
           81 |

amongst other errors.

I wonder. I actually do not use the bottled gcc from Homebrew on my system because I don’t have rights to install to /opt. But I can see if a brew reinstall helps. Maybe then it’ll link against new Xcode? Time for a multi-hour rebuild of gcc from source!

Yes that looks like Xcode rearranged headers. It might help to build GCC from source. However, the homebrew project might need to update their GCC patches for GCC to work.

Yeah. Poor Iain and FX, their lives become not fun when new XCode emerges. :frowning:

I’ll let you (all) know if the rebuild helps.

My Xcode also just upgraded to 16. Now I can’t build even a simple C++ only plain project with Homebrew GCC 14.2. Similar errors to you.

If I use G++ on the command line without CMake, I can build. If I use CMake, I cannot build. This is for a trivial C++ standalone test program. I will make an example Gist.

Even more fun, it’s like XCode 16 broke…awk? When I try to build Open MPI I get a lot of:

awk: not enough args in printf('%s\n' )
 input record number 1, file
 source line number 1

I am…impressed. I mean, this is 2020 awk:

❯ awk --version
awk version 20200816

But maybe the GCC build from Brew has an awk in some script? :man_shrugging:

Here’s a very minimal example reproducing the problem on macOS 14.6 and 15.0

Try workaround like

SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/ cmake -Bbuild

cmake --build build

that worked on the trivial project above. It seems that the current Homebrew GCC 14.2 doesn’t want the new 15.0 SDK that CMake grabs by default.

1 Like

I’ve had this problem on prior macOS/Xcode updates. My workaround until Homebrew updated its platform was to make a file ~/gcc.sh that I source when I want to use GCC. It contains:

export CC=gcc-14 CXX=g++-14 FC=gfortran-14

export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/
1 Like