Flutter not compiling in Ubuntu 22.04 & derivatives

Since upgrading to Ubuntu 22.04, the flutter snap no longer compiles for Linux:

flutter build linux

πŸ’ͺ Building with sound null safety πŸ’ͺ

CMake Error at /snap/flutter/111/usr/share/cmake-3.10/Modules/CMakeTestCXXCompiler.cmake:45 (message):
  The C++ compiler

    "/snap/flutter/current/usr/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/david/Source/inkworm/build/linux/x64/release/CMakeFiles/CMakeTmp

    Run Build Command:"/snap/flutter/current/usr/bin/ninja" "cmTC_29e5f"
    [1/2] Building CXX object CMakeFiles/cmTC_29e5f.dir/testCXXCompiler.cxx.o
    [2/2] Linking CXX executable cmTC_29e5f
    FAILED: cmTC_29e5f 
    : && /snap/flutter/current/usr/bin/clang++    -L/snap/flutter/current/usr/lib/gcc/x86_64-linux-gnu/8 -L/snap/flutter/current/usr/lib/x86_64-linux-gnu -lblkid -lgcrypt -llzma -lpthread -ldl -L/snap/flutter/current/usr/lib/ -L/snap/flutter/current/usr/lib/gcc/x86_64-linux-gnu/8 -L/snap/flutter/current/usr/lib/x86_64-linux-gnu -lblkid -lgcrypt -llzma -lpthread -ldl -L/snap/flutter/current/usr/lib/ CMakeFiles/cmTC_29e5f.dir/testCXXCompiler.cxx.o  -o cmTC_29e5f   && :
    /snap/flutter/current/usr/bin/ld: warning: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crt1.o: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0008002
    /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libgcc_s.so.1: undefined reference to `_dl_find_object@GLIBC_2.35'
    //lib/x86_64-linux-gnu/libgpg-error.so.0: undefined reference to `__libc_single_threaded@GLIBC_2.32'
    //lib/x86_64-linux-gnu/libgpg-error.so.0: undefined reference to `pthread_mutex_trylock@GLIBC_2.34'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.




  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)

I confirm after I upgraded to Ubuntu 22.04 I’m having the same exact issue, although β€œflutter doctor -v” reports everything is perfect:

flutter doctor -v [βœ“] Flutter (Channel stable, 3.0.0, on Ubuntu 22.04 LTS 5.15.0-27-generic, locale en_US.UTF-8) β€’ Flutter version 3.0.0 at /home/aboubakr/snap/flutter/common/flutter β€’ Upstream repository https://github.com/flutter/flutter.git β€’ Framework revision ee4e09cce0 (2 days ago), 2022-05-09 16:45:18 -0700 β€’ Engine revision d1b9a6938a β€’ Dart version 2.17.0 β€’ DevTools version 2.12.2

[βœ“] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) β€’ Android SDK at /home/aboubakr/Android/Sdk β€’ Platform android-32, build-tools 32.1.0-rc1 β€’ Java binary at: /home/aboubakr/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/212.5712.43.2112.8512546/jre/bin/java β€’ Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) β€’ All Android licenses accepted.

[βœ“] Chrome - develop for the web β€’ Chrome at google-chrome

[βœ“] Linux toolchain - develop for Linux desktop β€’ clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final) β€’ cmake version 3.10.2 β€’ ninja version 1.8.2 β€’ pkg-config version 0.29.1

[βœ“] Android Studio (version 2021.2) β€’ Android Studio at /home/aboubakr/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/212.5712.43.2112.8512546 β€’ Flutter plugin can be installed from: :hammer: ://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: :hammer: ://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[βœ“] IntelliJ IDEA Ultimate Edition (version 2022.1) β€’ IntelliJ at /home/aboubakr/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/221.5591.52 β€’ Flutter plugin version 67.1.4 β€’ Dart plugin version 221.5591.52

[βœ“] VS Code (version 1.64.2) β€’ VS Code at /usr/share/code β€’ Flutter extension can be installed from: :hammer: //marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[βœ“] Connected device (2 available) β€’ Linux (desktop) β€’ linux β€’ linux-x64 β€’ Ubuntu 22.04 LTS 5.15.0-27-generic β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 100.0.4896.75

[βœ“] HTTP Host Availability β€’ All required HTTP hosts are available

β€’ No issues found!