I try to build a demo project (hello.cpp, this program just outputs ‘hello’) with cmake + Ninja on my MacOS 15.
CMakeList.txt
looks like
project(BasicUsage)
cmake_minimum_required(VERSION 3.10)
add_executable(hello hello.cpp)
I use cmake -B build -G Ninja
and cd build && Ninja
. It turned out that the compiler seems unable to find the system libraries.
/Library/Developer/CommandLineTools/usr/bin/c++ -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk -MD -MT CMakeFiles/hello.dir/hello.cpp.o -MF CMakeFiles/hello.dir/hello.cpp.o.d -o CMakeFiles/hello.dir/hello.cpp.o -c '/Users/<name>/scripts/hello.cpp'
/Users/<name>/scritps/hello.cpp:1:10: fatal error: 'cstdio' file not found
1 | #include <cstdio>
| ^~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
In fact, the cstdio
lib is in /Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk/usr/include/c++/v1
. And it should be accessible when specifying isysroot
.
I find a possible solution given by GPT-4 by alternatively specifying the isystem
parameter when calling cmake.
cmake -B build -G Ninja -DCMAKE_CXX_FLAGS="-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
Then everything is fine.
Can anyone explain all these? I guess the problem is due to the search policy when specifying isysroot
. I don’t know if it is true.
By the way, this cmake file can work properly in Ubuntu even when I don’t include isystem
parameter.
Johnny Bryant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.