Today I upgraded my laptop to macOS 14.7.2 (Sonoma) from something like 14.5-or-6-ish. This triggered an upgrade to Xcode version 16.2 and its command line tools.
My c++ project continues to build and run under Xcode. It should also be buildable with CMake. But that stopped working after today’s upgrade to Xcode 16.2. It fails to find standard c++ headers:
#include <iostream>
gets:
fatal error: 'iostream' file not found
I assume this has something to do with an updated c++ and locations of its header files. How can I get my CMake build working again?
[UPDATE]
The CMakeLists.txt file is:
cmake_minimum_required(VERSION 3.24)
project(quux LANGUAGES C CXX)
# Specify compiler optimization level
add_compile_options(-O3)
# Need this to use "ranges" in c++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Find installed Open3D, which exports Open3D::Open3D
find_package(Open3D REQUIRED)
add_executable(quux)
target_sources(quux PRIVATE main.cpp)
target_link_libraries(quux PRIVATE Open3D::Open3D)
I invoked the build with:
cmake -DOpen3D_ROOT=${HOME}/open3d_install .. ; make -j 12
[SECOND UPDATE]
Thanks to @Some programmer dude and @Alan Birtles for suggestions. Sorry I forgot to mention that the first thing I tried was deleting and rebuilding my CMake build
directory. I tried it a second time just be be sure:
cwr@Craigs-M1-MacBook-Pro build % cd ..
cwr@Craigs-M1-MacBook-Pro quux % rm -rf build
cwr@Craigs-M1-MacBook-Pro quux % mkdir build
cwr@Craigs-M1-MacBook-Pro quux % cd build
cwr@Craigs-M1-MacBook-Pro build % cmake -DOpen3D_ROOT=${HOME}/open3d_install .. ; make -j 12
-- 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: /Library/Developer/CommandLineTools/usr/bin/cc - 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: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at /Users/cwr/open3d_install/lib/cmake/Open3D/Open3DConfig.cmake:18 (cmake_policy):
The OLD behavior for policy CMP0072 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
CMakeLists.txt:45 (find_package)
-- Found Open3D: /Users/cwr/open3d_install/lib/cmake/Open3D/Open3DConfig.cmake (found version "0.18.0")
-- Configuring done (0.7s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/cwr/Documents/code/quux/build
[ 50%] Building CXX object CMakeFiles/quux.dir/main.cpp.o
In file included from /Users/cwr/Documents/code/quux/main.cpp:37:
In file included from /Users/cwr/Documents/code/quux/quux.h:12:
In file included from /Users/cwr/Documents/code/quux/Agent.h:13:
In file included from /Users/cwr/Documents/code/quux/Vec3.h:14:
/Users/cwr/Documents/code/quux/Utilities.h:18:10: fatal error: 'iostream' file not found
18 | #include <iostream>
[THIRD UPDATE]
The only thing that changed on my laptop was a “point” update to a new macOS Sonoma version. My CMake installation (via Brew) and my own code were unchanged.
So I tried asking over on the Apple Developer Forums. The one response gave a useful test, which verified what I said above: building with Xcode (or as suggested, compiling directly from the command line) works fine, using CMake does not.
I would love to hear from a Mac-using CMake expert who could shed any light.
Was having the exact same issue, with the same Sonoma update and XCode version. In my case, I was upgrading from Ventura.
I ended up completely uninstalling the old XCode and reinstalling it again.
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
Not sure if this is an option for you, but it did solve the issues I was experiencing with the cstdint
header not being found while I was building an old version of PyArrow from source.
Adding in some additional details from OP's comment:
After xcode-select --install
it said xcode-select: note: install requested for command line developer tools
. It might have been OK but I forgot to re-build my build
folder. I went to System Settings looking for a way to install new command line tools, but found only updates for Safari and Sonoma 14.7.3. I installed those, re-made my build
folder, and then my project build and ran as before.