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

**URL:** https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711
**Category:** Code
**Created:** [September 17, 2024, 4:38pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711 "2024-09-17T16:38:01Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [September 17, 2024, 4:38pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/1 "2024-09-17T16:38:01Z")

</div>

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:

```bash
❯ 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:

```bash
❯ 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
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:

```bash
❯ 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:

```bash
❯ 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](https://gitlab.kitware.com/cmake/cmake/-/issues/26301), but this seems more…basic and boring.

* * *

I’m using CMake 3.30.3:

```auto
❯ cmake --version
cmake version 3.30.3

```

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [September 17, 2024, 5:14pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/2 "2024-09-17T17:14:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [September 17, 2024, 5:23pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/3 "2024-09-17T17:23:42Z")

</div>

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

```shell
        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!

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [September 17, 2024, 5:34pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/4 "2024-09-17T17:34:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [September 17, 2024, 5:51pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/5 "2024-09-17T17:51:10Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [September 17, 2024, 6:28pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/6 "2024-09-17T18:28:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [September 17, 2024, 6:30pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/7 "2024-09-17T18:30:57Z")

</div>

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

```auto
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:

```auto
❯ awk --version
awk version 20200816

```

But maybe the GCC build from Brew has an `awk` in some script? 🤷‍♂️

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [September 17, 2024, 7:11pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/8 "2024-09-17T19:11:40Z")

</div>

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

> <https://gist.github.com/scivision/d69faebbc56da9714798087b56de925a>

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [September 17, 2024, 7:22pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/9 "2024-09-17T19:22:48Z")

</div>

Try workaround like

```sh
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.

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [September 17, 2024, 7:25pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711/10 "2024-09-17T19:25:29Z")

</div>

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:

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

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

```
