Clang cannot locate standard header files

Bug #1242300 reported by Mike Pedersen on 2013-10-20
This bug affects 36 people
Affects Status Importance Assigned to Milestone
llvm-defaults (Debian)
Fix Released
llvm-defaults (Ubuntu)

Bug Description

This command fails saying that limits.h cannot be found:
echo '#include <limits.h>' | clang -v -xc -o /dev/null -

This is the full verbose output from it:
Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
 "/usr/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.23.2 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.2 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.2/include -internal-isystem /usr/include/clang/3.2/include/ -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/mike -ferror-limit 19 -fmessage-length 205 -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/--n2pM6N.o -x c -
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/clang/3.2/include"
ignoring duplicate directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
In file included from <stdin>:1:
/usr/include/limits.h:124:16: fatal error: 'limits.h' file not found
# include_next <limits.h>

Now, my first thought was that my limits.h file had been deleted somehow, but running "locate limits.h" shows that there is a limits.h in /usr/include, which clang searches through according to the verbose output.

This has only been a problem since upgrading to Ubuntu 13.10.

ProblemType: Bug
DistroRelease: Ubuntu 13.10
Package: clang 1:3.2-20
ProcVersionSignature: Ubuntu 3.11.0-12.19-generic 3.11.3
Uname: Linux 3.11.0-12-generic x86_64
NonfreeKernelModules: fglrx
ApportVersion: 2.12.5-0ubuntu2
Architecture: amd64
Date: Sun Oct 20 12:21:43 2013
InstallationDate: Installed on 2013-04-02 (200 days ago)
InstallationMedia: Ubuntu 12.10 "Quantal Quetzal" - Release amd64 (20121017.5)
MarkForUpload: True
SourcePackage: llvm-defaults
UpgradeStatus: Upgraded to saucy on 2013-10-17 (2 days ago)

Mike Pedersen (noctune) wrote :
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in llvm-defaults (Ubuntu):
status: New → Confirmed
baltasarq (baltasarq) wrote :

Same here. Trying to compile the simplest hello world:

#include <stdio.h>

int main()
  printf( "Hola!");


$ clang hello.c
In file included from hello.c:1:
/usr/include/stdio.h:33:11: fatal error: 'stddef.h' file not found
# include <stddef.h>
1 error generated.

$ uname -a
Linux PC-baltasarq 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Operating system flavour is Lubuntu 13.10
Machine is x64

Kevin Funk (kfunk) wrote :

Bump. Upgrading to clang-3.4 seems to fix this. Why are you guys still have clang-3.2 as default anyway? That's almost an year-old release.

Mike Pedersen (noctune) wrote :

clang-3.4 isn't fully released yet, is it? I think it's still work in progress, and it isn't in the package manager (not even in sid).

information type: Public → Public Security
Ulrik Mikaelsson (rawler) wrote :

3.3 and 3.4 gives me another problem;
/usr/lib/gcc/i686-linux-gnu/4.8/../../../../include/c++/4.8/string:38:10: fatal error:
      'bits/c++config.h' file not found

Igor Petrovski (i-petrovski) wrote :

I am getting
/usr/include/wchar.h:39:11: fatal error: 'stdarg.h' file not found

Does not matter, which clang version I use

Changed in llvm-defaults (Ubuntu):
importance: Undecided → High
status: Confirmed → Triaged
Nick Andrik (andrikos) wrote :

There is a wlrokround from a duplicate of this bug:

Kirit Sælensminde (kayess) wrote on 2013-10-22: #5

The following seems to work as a workaround for me:

cd /usr/lib/clang/3.2/
sudo ln -s /usr/lib/llvm-3.2/lib/clang/3.2/include

It looks like there's a mismatch between where the include files are installed to and where clang expects to find them

Diagnosed with the help of:

echo '#include <stdarg.h>' | clang -xc -v -

affects: llvm-toolchain-3.2 (Debian) → llvm (Debian)
affects: llvm (Debian) → llvm-defaults (Debian)
Changed in llvm-defaults (Debian):
status: Unknown → New
Mike Henry (mike-henry) wrote :

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.

Rory Yorke (ryorke) wrote :

I think the correct related Debian bug is

I did a 'sudo aptitude purge libclang-common-dev', accepted the first dependency resolution option (remove clang and clang-3.2), and then did 'sudo aptitude install clang'; now clang works again. I'm not familiar with apt/dpkg details; perhaps 'sudo aptitude reinstall libclang-common-dev' would work too.

I'm on Xubuntu 13.10, which I upgraded from 13.04 -- I think this matches the description of the above bug (directory not replaced by symlink on upgrade).

Václav Haisman (vzeman79) wrote :

#10 has worked for me as well.

Changed in llvm-defaults (Debian):
status: New → Fix Released
orian (pawelszczur) wrote :
Download full text (3.6 KiB)

I've upgraded to trusty yesterday and the looks like the bug is still there. clang++ cannot link anything because:

clang++ -v -E -o cennik
Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8.2
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7.3
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Candidate multiilb: .;@m64
Candidate multiilb: 32;@m32
Selected multilib: .;@m64
 "/usr/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -E -disable-free -disable-llvm-verifier -main-file-name -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.24 -v -resource-dir /usr/bin/../lib/clang/3.5 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.5/include -internal-externc-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/orian/workspace/cpp/oi -ferror-limit 19 -fmessage-length 190 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o cennik -x c++
clang -cc1 version 3.5 based upon LLVM 3.5 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/x86_64-linux-gnu"


orian (pawelszczur) wrote :

A workaround for now:

sudo aptitude install libstdc++6=4.8.2-19ubuntu1

I found it by accident when trying to install gcc-snapshot. The gcc-snapshot suggested downgrading libstdc++, I've canceled installation and downgraded libstdc++.

Nathan Kurz (a-nate) wrote :

I was just bitten by this. I tried to upgrade from clang-3.4 to clang-3.5, and was unable to compile anything because the standard headers were not found. I then downgraded back to clang-3.4, and was surprised to find that to be broken as well. Since at that point I was stuck, I plowed on until I found a solution.

The issue seems related to the fact that gcc-4.9 exists at this point in time, but g++-4.9 does not. I think this means it only affects those who have partially upgraded to gcc-4.9 (the C compiler, but not the C++ compiler). Clang is searching for the standard C++ header in directories that don't exist and not finding them. There also seem to be issues where Clang is searching only for /usr/include/c++ without adding an appropriate version number.

One fix is to add symlinks until Clang can find the files it's looking for.

The currently searched header directories can be found with:
clang++ -E -x c++ - -v < /dev/null

Assuming a test file 'file.cpp' that includes a failing header, you can see where g++ is successfully finding a header (and Clang is failing) like this:
strace -f g++ file.cpp -std=gnu++11 -o file.o 2>&1 | grep header
strace -f clang++ file.cpp -std=gnu++11 -o file.o 2>&1 | grep header

There are several ways of helping Clang to find the headers it is looking for, all of varying degree of likelihood to break other things. I decided the path of least harm was to create symlinks like this:

$ ls -l /usr/include/c++/
lrwxrwxrwx 1 root root 3 Dec 20 15:50 backward -> 4.8
lrwxrwxrwx 1 root root 37 Dec 20 15:56 x86_64-linux-gnu -> /usr/include/x86_64-linux-gnu/c++/4.8

Once you solve the issue of finding header files, you then won't be able to find I fixed that with this:
sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.8 /usr/local/lib/x86_64-linux-gnu

Now that I've done this, both clang-3.4 and clang-3.5 will work, although not simultaneously because Ubuntu supports multiple versions of GCC but not of Clang. Note that this is just an ugly workaround for a bug that should be fixed by Ubuntu. Once this is fixed, these steps will be unnecessary, and possibly hazardous. Personally, I think that Ubuntu should support having multiple versions of Clang installed, and rather than deinstalling one version to install another.

Tzafrir (tzaf) wrote :

I have the exact same problem as #14, and the propsed fix worked

Andrew Poltavets (xoomer) wrote :

Yep, I have same problem after upgrading 14.10 to 15.04 beta. Since final release has been happened in april bug still present at now. I have both 3.5 and 3.6 clang compilers installed.

Tomas Angelo (tommyangelo) wrote :

In Ubuntu 14.04 LTS I installed Clang 3.7 after adding new official repository from

Then based on this thread:
I tried backport the latest packages

I add ppa repository:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test

Refreshed my repositories:
sudo apt-get update

And finally installed (ideally) latest toolchain:
sudo apt-get install g++-5

Everything works fine when compiling as follows:
clang++-3.7 -std=c++14 main.cpp

What I left unresolved is using choose of default compiler. But more information can be found in thread:

This should be fixed in at least vivid+ releases

Changed in llvm-defaults (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public Security information  Edit
Everyone can see this security related information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.