HelloWorldITK on macOS Sequoia 15.0.1 cannot find stdio.h

On macOS 15.0.1, I’m building up to compiling the HelloWorldITK code by starting with the very basic HelloWorld that works just fine.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(HelloWorld) 
add_executable(${PROJECT_NAME} main.cxx)

main.cxx:

#include <iostream>
int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

But even without adding #include "itkImage.h" to main.cxx, when I just add this to CMakeLists.txt:

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

After cmake .. and make, I get errors like

% make
[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/main.cxx.o
In file included from HelloWorld/main.cxx:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/iostream:43:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/ios:223:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__memory/shared_ptr.h:14:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__compare/compare_three_way.h:13:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__compare/three_way_comparable.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__compare/common_comparison_category.h:15:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/cstddef:46:5: error: tried including <stddef.h> but didn’t find libc++'s <stddef.h> header. This usually means that your header search paths are not configured properly. The header search paths should contain the C++ Standard Library headers before any C Standard Library, and you are probably using compiler flags that make that not be the case.

ITK was installed with homebrew

What happens if you add this to your CMakeLists.txt:

Thanks, Dženan. Adding that didn’t seem to change anything.

Using verbose cmake/make commands, I was able to see the compilation step:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ \
-DH5_BUILT_AS_DYNAMIC_LIB \
-DITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER \
-DITK_IMAGEIO_FACTORY_REGISTER_MANAGER \
-DITK_MESHIO_FACTORY_REGISTER_MANAGER \
-DITK_TRANSFORMIO_FACTORY_REGISTER_MANAGER \
-Dkiss_fft_scalar=double \
-I/Users/andy/HelloWorld/build/ITKFactoryRegistration \
-I/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include \
-isystem /usr/local/include \
-isystem /usr/local/include/gdcm-3.0 \
-isystem /usr/local/include/ITK-5.3 \
-isystem /usr/local/include/eigen3 \
-isystem /usr/local/include/vtk-9.3 \
-isystem /usr/local/include/vtk-9.3/vtkfreetype/include \
-std=c++14 \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk \
-mmacosx-version-min=15.0 \
-MD \
-MT CMakeFiles/HelloWorld.dir/main.cxx.o \ 
-MF CMakeFiles/HelloWorld.dir/main.cxx.o.d \
-o CMakeFiles/HelloWorld.dir/main.cxx.o \
-c /Users/andy/ITK/HelloWorld/main.cxx

That command works if I take out the line

-I/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include \

So it looks like the find_package(ITK REQUIRED) is adding more than it should. My computer is set to use MacOSX15.sdk – I don’t know where the “14” is coming from. But even if I change that line to use “15” instead, it gets the same error. ¯_(ツ)_/¯

Homebrew’s version might be compiled with v14 SDK.

Someone more familiar with MacOS might have advice. Maybe @seanm?

1 Like

Thanks for the tip! I was able to get it to work by adding these lines to CMakeLists.txt:

# Set the macOS deployment target
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.5" CACHE STRING "Minimum OS X deployment version")

# Specify the path to the desired SDK
set(CMAKE_OSX_SYSROOT /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk)

1 Like