Clang++ cannot compile a C++ program after do-release-upgrade to Jammy

Bug #1997600 reported by Jeffrey Walton
30
This bug affects 6 people
Affects Status Importance Assigned to Milestone
clang (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Hi Everyone.

I was running Ubuntu 20.04/Focal x86_64, fully patched. g++ and clang++ were installed and worked as expected. I ran do-release-upgrade to move to Ubuntu 22.04/Jammy. After Jammy g++ works but clang++ does not.

I performed a 'apt-get remove --purge clang*' followed by 'apt-get install clang'. No joy.

I manually installed libc++-abi and then libclang-cpp-dev. Still no joy.

Something is sideways with Clang on Ubuntu 22.04/Jammy. And I'm out of guesses.

-----

Here is the compile error I can't seem to shake - missing C++ headers. It looks like libc++ is not wired up correctly or libstdc++ is not wired up correctly. In either case, clang++ cannot seem to find the standard C++ headers or library.

$ clang++ -c test.cpp
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~
1 error generated.

$ cat test.cpp
#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
  std::string x(argv[0] ? argv[0] : "");
  std::cout << x << std::endl;
  return 0;
}

-----

And something more verbose:

$ clang++ -v -c test.cpp
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
 (in-process)
 "/usr/lib/llvm-14/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/jwalton -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/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/jwalton -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o test.o -x c++ test.cpp
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.
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.

-----

$ command -v g++
/usr/bin/g++

$ command -v clang++
/usr/bin/clang++

$ g++ --version
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.

$ clang++ --version
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy

$ apt-cache show clang
Package: clang
Architecture: amd64
Version: 1:14.0-55~exp2
Priority: optional
Section: universe/devel
Source: llvm-defaults (0.55~exp2)
Origin: Ubuntu
Maintainer: Ubuntu Developers <email address hidden>
Original-Maintainer: LLVM Packaging Team <email address hidden>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 25
Depends: clang-14 (>= 14~)
Breaks: clang-3.2, clang-3.3, clang-3.4 (<< 1:3.4.2-7~exp1), clang-3.5 (<< 1:3.5~+rc1-3~exp1)
Replaces: clang (<< 3.2-1~exp2), clang-3.2, clang-3.3, clang-3.4 (<< 1:3.4.2-7~exp1), clang-3.5 (<< 1:3.5~+rc1-3~exp1)
Filename: pool/universe/l/llvm-defaults/clang_14.0-55~exp2_amd64.deb
Size: 3558
MD5sum: 9012efb7d550940265a49a8b3b986b1d
SHA1: a27e72f7f3e0d3ba8a84cf9e5612849ef11a46d9
...

-----

Finally:

$ update-alternatives --list clang++
update-alternatives: error: no alternatives for clang++

Revision history for this message
Launchpad Janitor (janitor) wrote :

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

Changed in clang (Ubuntu):
status: New → Confirmed
Revision history for this message
Nicolas Simon (nimon77) wrote (last edit ):

An hotfix that worked for me is to install libstdc++-12-dev

Revision history for this message
Shuhao (shuhao) wrote :

This is also affecting clang-tidy, so if you use g++ normally to do development and use clang-tidy to check, this is causing it to all fail.

Revision history for this message
Shuhao (shuhao) wrote :

Also interesting is that this definitely worked before. I can reproduce this problem on multiple up-to-date jammy machines. However, on my ubuntu:jammy container, it worked (although my image is cached from about 5months ago).

Revision history for this message
Shuhao (shuhao) wrote :

This seems related: https://askubuntu.com/questions/1441844/todays-ubuntu-22-04-updates-seem-to-break-clang-compiler.

Can confirm that installing g++-12 solves this issue.

Revision history for this message
Kevin Lalumiere (klalumiere) wrote (last edit ):

I wrote a Stack Overflow answer on this issue: https://stackoverflow.com/a/74605488/3068259

Revision history for this message
Jerome Droniou (jdroniou) wrote :

I can also confirm that the problem occurs on Ubuntu 20.04 that was dist-upgraded to 22.04, but not on a clean install of 22.04. I have two machines, each with one of these installs, and on the one where 22.04 was installed from scratch my clang++ still works fine, but on the one that was upgraded 20.04->22.04, clang++ cannot find most of the standard header files (iostream, cassert, etc.).

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.