** Description changed:

  Summary
  =======
  Installing libgcc-16-dev alongside clang-N is enough to break clang++: it 
fails to link any C++ program with `ld: cannot find -lstdc++`. This happens 
even though the system default gcc is 15 and libstdc++-15-dev is available. 
libgcc-16-dev is routinely pulled in transitively (e.g. by libboost-all-dev via 
the fortran chain), so users hit this without ever asking for gcc-16.
  
  Steps to reproduce (clean ubuntu:26.04)
  =======================================
-     apt-get update
-     apt-get install -y --no-install-recommends clang-22 libgcc-16-dev
-     echo 'int main(){}' > /t.cpp
-     clang++-22 /t.cpp -o /t
+ apt-get update
+ apt-get install -y --no-install-recommends clang-22 libgcc-16-dev
+ echo 'int main(){}' > /t.cpp
+ clang++-22 /t.cpp -o /t
+ 
+ Alternate reproduction (Dockerfile)
+ ===================================
+ The following Dockerfile reproduces the failure self-contained;
+ `docker build` fails on the final layer (that failure IS the reproduction):
+ 
+     FROM ubuntu:26.04
+     RUN apt-get update \
+      && DEBIAN_FRONTEND=noninteractive apt-get install -y 
--no-install-recommends \
+           clang-22 libgcc-16-dev \
+      && rm -rf /var/lib/apt/lists/*
+     RUN echo 'int main() { return 0; }' > /t.cpp \
+      && clang++-22 /t.cpp -o /t
  
  Expected
  ========
  Linking succeeds (default gcc is 15 and libstdc++-15-dev provides libstdc++).
  
  Actual
  ======
-     clang++-22: warning: future releases of the clang compiler will prefer 
GCC installations containing libstdc++ include directories; 
'/usr/lib/gcc/x86_64-linux-gnu/15' would be chosen over 
'/usr/lib/gcc/x86_64-linux-gnu/16' [-Wgcc-install-dir-libstdcxx]
-     /usr/bin/x86_64-linux-gnu-ld.bfd: cannot find -lstdc++: No such file or 
directory
-     clang++-22: error: linker command failed with exit code 1
+ clang++-22: warning: future releases of the clang compiler will prefer GCC 
installations containing libstdc++ include directories; 
'/usr/lib/gcc/x86_64-linux-gnu/15' would be chosen over 
'/usr/lib/gcc/x86_64-linux-gnu/16' [-Wgcc-install-dir-libstdcxx]
+ /usr/bin/x86_64-linux-gnu-ld.bfd: cannot find -lstdc++: No such file or 
directory
+ clang++-22: error: linker command failed with exit code 1
  
  Root cause
  ==========
  libgcc-16-dev populates /usr/lib/gcc/x86_64-linux-gnu/16/ with the GCC 
runtime objects (crtbegin.o, libgcc.a). clang's GCC-installation detector 
selects the highest-versioned directory containing those objects (16 over 15) 
and assumes libstdc++ lives in the same prefix. Since libstdc++-16-dev is not 
installed, -lstdc++ cannot be found. gcc-16-base on its own does NOT trigger 
this (it creates no runtime dir); libgcc-16-dev is the minimal trigger.
  
  The clang heuristic itself is being addressed upstream in LLVM
  (https://github.com/llvm/llvm-project/pull/145056 - "Take libstdc++ into
  account during GCC detection"; the -Wgcc-install-dir-libstdcxx warning
  above comes from that work, and a future release will prefer the
  complete dir, i.e. 15). This report is about the Ubuntu packaging
  experience: a default clang install silently lands in a non-linkable
  state via ordinary transitive deps.
  
  Suggested fixes (packaging side)
  ================================
  - Ship a clang driver default that pins --gcc-install-dir to the distro 
default gcc, or
  - Have the clang package Depend/Recommend a matching libstdc++ for the 
highest installable gcc runtime, or
  - Document the libstdc++-<N>-dev requirement prominently.
  
  Environment
  ===========
  - Ubuntu 26.04
  - clang-22 (llvm-toolchain-22), default gcc 15.2.0, gcc-16-base 16-20260322
  - Reproduced in a clean ubuntu:26.04 container.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2154746

Title:
  Installing libgcc-16-dev and clang-N together breaks clang++ (cannot
  find -lstdc++)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/llvm-toolchain-22/+bug/2154746/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to