pkgsStatic clang works for C but not C++

Here is a reproducible example showing pkgsStatic.buildPackages.llvmPackages_21.clang can be used to compile hello world with x86_64-unknown-linux-musl-clang but not x86_64-unknown-linux-musl-clang++. This has to be a bug right? Or am I misunderstanding how this package is intended to work?

flake:

{
  description = "Python development environment";

  inputs = {
    # Use the stable nixos channel
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
  };

  outputs = { self, nixpkgs }:
    let
      # Systems supported
      supportedSystems = [ "x86_64-linux" "aarch64-linux" ];

      # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

      # Get nixpkgs legacyPackages for each system
      pkgsFor = system: nixpkgs.legacyPackages.${system};
    in
      {
        devShells = forAllSystems (system:
          let
            pkgs = pkgsFor system;
          in
            {
              default = pkgs.mkShell {
                buildInputs = with pkgs; [
                  #llvmPackages_21.clang
                  pkgsStatic.buildPackages.llvmPackages_21.clang
                ];
              };
            }
        );
      };
}

flake.lock:

{
  "nodes": {
    "nixpkgs": {
      "locked": {
        "lastModified": 1763622513,
        "narHash": "sha256-1jQnuyu82FpiSxowrF/iFK6Toh9BYprfDqfs4BB+19M=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "c58bc7f5459328e4afac201c5c4feb7c818d604b",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-25.05",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}

hello.c

#include <stdio.h>

int main()
{
    printf("hello world\n");
    return 0;
}
$ x86_64-unknown-linux-musl-clang /tmp/hello.c
$ echo $?
0
$ x86_64-unknown-linux-musl-clang++ /tmp/hello.c
clang++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: warning: libc.so.6, needed by /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1, not found (try using -rpath or -rpath-link)
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: warning: ld-linux-x86-64.so.2, needed by /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1, not found (try using -rpath or -rpath-link)
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `memset@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `strlen@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `pthread_setspecific@GLIBC_2.34'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `mmap@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `pthread_cond_broadcast@GLIBC_2.3.2'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `pthread_getspecific@GLIBC_2.34'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `pthread_once@GLIBC_2.34'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `getpagesize@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `pthread_mutex_lock@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `realloc@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `pthread_cond_wait@GLIBC_2.3.2'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `calloc@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `pthread_mutex_unlock@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `malloc@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `pthread_key_create@GLIBC_2.34'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `__tls_get_addr@GLIBC_2.3'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `memmove@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `abort@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `memcpy@GLIBC_2.14'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `munmap@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `free@GLIBC_2.2.5'
/nix/store/b3r9l2qyr78nwy903kn4d5zlp6kyhg73-x86_64-unknown-linux-musl-binutils-2.44/bin/x86_64-unknown-linux-musl-ld: /nix/store/d84l3qjb077dxkajn24k58z2q261d4lv-gcc-14.3.0-libgcc/lib/libgcc_s.so.1: undefined reference to `_dl_find_object@GLIBC_2.35'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
1 Like

How does setting stdenv work if you need more than one compiler? For CI I’d like to setup both clang and gcc builds. Do I have to do that with separate flakes/shells?