Clang Error - stddef file not found?

38k Views Asked by At

After upgrading to Ubuntu 13.10 "Saucy", Clang now gives me the error message:

clang -Wall -Werror -std=c99 -ggdb -O0 5.1.c -o 5.1
In file included from 5.1.c:1:
/usr/include/stdio.h:33:11: fatal error: 'stddef.h' file not found
# include <stddef.h>
          ^
1 error generated.
make: *** [5.1] Error 1

BTW the header I included was stdio.h not stddef.h but I am assuming that stdio.h references or #includes stddef.h

7

There are 7 best solutions below

1
On

It's a know bug in ubuntu. Take a look here: https://bugs.launchpad.net/ubuntu/+source/llvm-defaults/+bug/1242300

It appears that a temporary workaround is to correct the symlink:

For the 3.5 LLVM toolchain it seems that the symlink /usr/lib/clang/3.5/include erroneously points to ../../llvm-3.4/lib/clang/3.5/include, but should instead point to ../../llvm-3.5/lib/clang/3.5/include

The workaround (of course) is to manually correct the symlink.

For the 3.4 toolchain the /usr/lib/clang/3.4/include doesn't exist at all. I have not tried LLVM 3.4 on Ubuntu so I don't know if createing a symlink to ../../llvm-3.4/lib/clang/3.4/include will fix the problem, but it does seem likely.

Source

0
On

I've encountered this with a Debian 12 (Bookworm) Docker container where I had been running Doxygen with clang-assisted parsing. I'd built my container to install the latest clang (clang-18) from LLVM's APT repo as well as the default version of gcc and g++ for Debian 12 (gcc-12 g++-12).

Removing the LLVM APT repo caused the default clang-14 package to be installed and that has resolved the include error.

I guess don't try to install a clang version much newer than your system's GCC toolchain?

0
On

In my case, This is because of the file compile_commands.json dont exist, just

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .

solve it.

2
On

This error appeared for me when trying to run clang-tidy without clang installed.

Installing clang fixed this error. IMO this error occurs when clang-tidy looks for headers in GCC and system paths and clang version/symlink of these headers are missing.

0
On

Using clang-tidy from cmake and gcc you can add the following in your CMakeLists.txt

if(CMAKE_EXPORT_COMPILE_COMMANDS)
    set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

This will result in the "compile_commands.json" file to contain the correct gcc includes.

The solution comes from the kitware issue tracker: Missing c++ header path in compile_commands.json

This answer is a bit off topic but this is the top hit on search engines for my specific issue

0
On

For clang16, You might try this:

export CPLUS_INCLUDE_PATH=/usr/lib/llvm-16/lib/clang/16/include/

(substitute the 'llvm-16/lib/clang/16' with the actual version you installed)

0
On

Please note that I resolved the above error by performing:

$ sudo apt-get install clang

In my particular case, there is likely an issue with something in my cmake files which I haven't determined yet.