clang fails to find C++ headers in presence of gcc-12 package

Bug #2009223 reported by Ratchanan Srirattanamet
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
llvm-toolchain-14 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

This is a weird one. On a clean rootfs (e.g. with `docker run -it --rm ubuntu:22.04`), clang can find C++ headers just fine.

```
# apt update; apt install --no-install-recommends clang
<snip>
# echo '#include <iostream>' | clang -x c++ -E - >/dev/null
#
```

But as soon as gcc-12 is also installed on the system (which can be pulled in by e.g. dkms), the exact same "source" doesn't pre-process anymore.

```
# apt install --no-install-recommends gcc-12
<snip>
# echo '#include <iostream>' | clang -x c++ -E - >/dev/null
<stdin>:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.
#
```

Upon further inspection, it seems like it just looks for headers in non-existent path, and somehow has "12" in it (but the resolved path isn't?)

```
# echo '#include <iostream>' | clang -x c++ -E -Wp,-v - >/dev/null
clang -cc1 version 14.0.0 based upon LLVM 14.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/backward"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++
 /usr/lib/llvm-14/lib/clang/14.0.0/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
<stdin>:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.
```

It almost seems like clang tries to detect the highest installed version of GCC, but doesn't prepare for the fact that g++ 12 isn't installed. So, I'm not sure who's at fault here...

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: clang-14 1:14.0.0-1ubuntu1
Uname: Linux 6.1.11-gitv6.1.11-1-gb07abe8e29e1 x86_64
NonfreeKernelModules: nvidia_modeset nvidia
ApportVersion: 2.20.11-0ubuntu82.3
Architecture: amd64
CasperMD5CheckResult: unknown
CurrentDesktop: ubuntu:GNOME
Date: Sat Mar 4 01:17:58 2023
InstallationDate: Installed on 2021-03-15 (718 days ago)
InstallationMedia: Ubuntu 20.04.2.0 LTS "Focal Fossa" - Release amd64 (20210209.1)
ProcEnviron:
 TERM=xterm-256color
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=th_TH.UTF-8
 SHELL=/bin/bash
RebootRequiredPkgs: Error: path contained symlinks.
SourcePackage: llvm-toolchain-14
UpgradeStatus: Upgraded to jammy on 2022-10-22 (132 days ago)

Revision history for this message
Ratchanan Srirattanamet (peat-new) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

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

Changed in llvm-toolchain-14 (Ubuntu):
status: New → Confirmed
Revision history for this message
Tom (tom-sogetthis) wrote :

The same happens on Ubuntu 20.04 with clang-10 and gcc-10 (when gcc-10 is installed in addition to default gcc-9).

Revision history for this message
Tom (tom-sogetthis) wrote :

This problem happens when you install "gcc-12" package.

If you install "g++-12" package instead, there is no problem.

"gcc-12" package does not install C++ standard library, while "g++-12" package does install it.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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