Compiling Mesa fails with: `stdlib.h: No such file or directory`

Hi, I am trying to Compile the latest mesa, however I got stuck on the following error:

Found ninja-1.9.0.git.kitware.dyndep-1.jobserver-1 at /System/Index/bin/ninja
[431/2641] Generating src/vulkan/overlay-layer/overlay.frag.spv.h with a custom command
../src/vulkan/overlay-layer/overlay.frag
[436/2641] Generating src/vulkan/overlay-layer/overlay.vert.spv.h with a custom command
../src/vulkan/overlay-layer/overlay.vert
[602/2641] Compiling C++ object src/amd/llvm/libamd_common_llvm.a.p/ac_llvm_helper.cpp.o
FAILED: src/amd/llvm/libamd_common_llvm.a.p/ac_llvm_helper.cpp.o 
c++ -Isrc/amd/llvm/libamd_common_llvm.a.p -Isrc/amd/llvm -I../src/amd/llvm -Iinclude -I../include -Isrc -I../src -Isrc/mapi -I../src/mapi -Isrc/mesa -I../src/mesa -I../src/gallium/include -Isrc/gallium/auxiliary -I../src/gallium/auxiliary -Isrc/compiler -I../src/compiler -Isrc/amd -I../src/amd -Isrc/amd/common -I../src/amd/common -Isrc/compiler/nir -I../src/compiler/nir -I/usr/include/libdrm -I/usr/include/valgrind -fvisibility=hidden -flto=16 -fdiagnostics-color=always -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++14 -O3 -ffunction-sections -fdata-sections '-DPACKAGE_VERSION="21.3.7"' '-DPACKAGE_BUGREPORT="https://gitlab.freedesktop.org/mesa/mesa/-/issues"' -DUSE_ELF_TLS -DHAVE_ST_VDPAU -DENABLE_ST_OMX_BELLAGIO=0 -DENABLE_ST_OMX_TIZONIA=0 -DHAVE_VA_SURFACE_ATTRIB_DRM_FORMAT_MODIFIERS -DHAVE_X11_PLATFORM -DHAVE_XCB_PLATFORM -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DGLX_USE_DRM -DHAVE_DRM_PLATFORM -DENABLE_SHADER_CACHE -DHAVE___BUILTIN_BSWAP32 -DHAVE___BUILTIN_BSWAP64 -DHAVE___BUILTIN_CLZ -DHAVE___BUILTIN_CLZLL -DHAVE___BUILTIN_CTZ -DHAVE___BUILTIN_EXPECT -DHAVE___BUILTIN_FFS -DHAVE___BUILTIN_FFSLL -DHAVE___BUILTIN_POPCOUNT -DHAVE___BUILTIN_POPCOUNTLL -DHAVE___BUILTIN_UNREACHABLE -DHAVE_FUNC_ATTRIBUTE_CONST -DHAVE_FUNC_ATTRIBUTE_FLATTEN -DHAVE_FUNC_ATTRIBUTE_MALLOC -DHAVE_FUNC_ATTRIBUTE_PURE -DHAVE_FUNC_ATTRIBUTE_UNUSED -DHAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT -DHAVE_FUNC_ATTRIBUTE_WEAK -DHAVE_FUNC_ATTRIBUTE_FORMAT -DHAVE_FUNC_ATTRIBUTE_PACKED -DHAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL -DHAVE_FUNC_ATTRIBUTE_ALIAS -DHAVE_FUNC_ATTRIBUTE_NORETURN -DHAVE_FUNC_ATTRIBUTE_VISIBILITY -DHAVE_UINT128 -DUSE_SSE41 -DUSE_GCC_ATOMIC_BUILTINS -DUSE_X86_64_ASM -DMAJOR_IN_SYSMACROS -DHAS_SCHED_H -DHAS_SCHED_GETAFFINITY -DHAVE_LINUX_FUTEX_H -DHAVE_ENDIAN_H -DHAVE_DLFCN_H -DHAVE_SYS_SHM_H -DHAVE_CET_H -DHAVE_STRTOF -DHAVE_MKOSTEMP -DHAVE_TIMESPEC_GET -DHAVE_MEMFD_CREATE -DHAVE_RANDOM_R -DHAVE_FLOCK -DHAVE_STRTOK_R -DHAVE_GETRANDOM -DHAVE_QSORT_R -DHAVE_PROGRAM_INVOCATION_NAME -DHAVE_POSIX_MEMALIGN -DHAVE_DIRENT_D_TYPE -DHAVE_STRTOD_L -DHAVE_DLADDR -DHAVE_DL_ITERATE_PHDR -DHAVE_ZLIB -DHAVE_ZSTD -DHAVE_COMPRESSION -DHAVE_PTHREAD -DHAVE_PTHREAD_SETAFFINITY -DHAVE_LIBDRM -DLLVM_AVAILABLE '-DMESA_LLVM_VERSION_STRING="13.0.1"' -DLLVM_IS_SHARED=1 -DDRAW_LLVM_AVAILABLE -DUSE_LIBGLVND=1 -DHAVE_VALGRIND -DMESA_EXECMEM -DHAVE_LIBUNWIND -DHAVE_WAYLAND_PLATFORM -DWL_HIDE_DEPRECATED -DHAVE_OPENMP -DHAVE_DRI3 -DHAVE_DRI3_MODIFIERS -DHAVE_GALLIUM_EXTRA_HUD=1 -DHAVE_LIBSENSORS=1 -DVK_USE_PLATFORM_DISPLAY_KHR -Werror=return-type -Werror=empty-body -Wno-non-virtual-dtor -Wno-missing-field-initializers -Wno-format-truncation -fno-math-errno -fno-trapping-math -flifetime-dse=1 -Werror=format -Wformat-security -O2 -fomit-frame-pointer -pipe -fPIC -pthread -isystem/System/Index/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -MD -MQ src/amd/llvm/libamd_common_llvm.a.p/ac_llvm_helper.cpp.o -MF src/amd/llvm/libamd_common_llvm.a.p/ac_llvm_helper.cpp.o.d -o src/amd/llvm/libamd_common_llvm.a.p/ac_llvm_helper.cpp.o -c ../src/amd/llvm/ac_llvm_helper.cpp
In file included from /System/Index/include/c++/9.2.0/ext/string_conversions.h:41,
                 from /System/Index/include/c++/9.2.0/bits/basic_string.h:6493,
                 from /System/Index/include/c++/9.2.0/string:55,
                 from /System/Index/include/llvm/Support/ErrorHandling.h:18,
                 from /System/Index/include/llvm/ADT/Hashing.h:48,
                 from /System/Index/include/llvm/ADT/ArrayRef.h:12,
                 from /System/Index/include/llvm/ADT/BitVector.h:16,
                 from /System/Index/include/llvm/Analysis/TargetLibraryInfo.h:12,
                 from ../src/amd/llvm/ac_llvm_helper.cpp:27:
/System/Index/include/c++/9.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
   75 | #include_next <stdlib.h>
      |               ^~~~~~~~~~
compilation terminated.
[619/2641] Linking target src/vulkan/overlay-layer/libVkLayer_MESA_overlay.so
ninja: build stopped: subcommand failed.
Compile: Mesa 21.3.7 - Build failed.

The file /System/Index/include/c++/9.2.0/stdlib.h does exist though.

I know we have a workaround for cmake in place: Recipes/01-replace-isystem_with-I.patch at master · gobolinux/Recipes · GitHub

But yeah obviously that did not fix this specific issue. But it might have something to do with -isystem/-I? I do not reall know a lot about it.

Also this cmake bug report might be of interest: Detect GCC system include paths at run-time and automatically add them to CMAKE_${LANG}_IMPLICIT_INCLUDE_DIRECTORIES (#16291) · Issues · CMake / CMake · GitLab

I hope somebody knows how this might be tackled in the Recipe, or maybe by “further” fixing our cmake configuration.

Take a look at my recipe, it could help.

Mesa Recipe

1 Like

Yes thank you, setting CPLUS_INCLUDE_PATH="/System/Index/include/c++/9.2.0:/System/Index/include:$CPLUS_INCLUDE_PATH" helped.