Flutter linux 在 Ubuntu 22.04 LTS CMake 上构建错误

Mif*_*zak 5 ubuntu flutter flutter-desktop flutter-linux

我有flutter项目,可以在Ubuntu 20.04上成功构建。现在我想在 Ubuntu 22.04 上构建它,但出现 CMake 错误。

\n
CMake Error at /snap/flutter/111/usr/share/cmake-3.10/Modules/CMakeTestCXXCompiler.cmake:45 (message):\n  The C++ compiler\n\n    "/snap/flutter/current/usr/bin/clang++"\n\n  is not able to compile a simple test program.\n\n  It fails with the following output:\n\n    Change Dir: /home/arzak/StudioProjects/testlinux/build/linux/x64/debug/CMakeFiles/CMakeTmp\n\n    Run Build Command:"/snap/flutter/current/usr/bin/ninja" "cmTC_38e6c"\n    [1/2] Building CXX object CMakeFiles/cmTC_38e6c.dir/testCXXCompiler.cxx.o\n    [2/2] Linking CXX executable cmTC_38e6c\n    FAILED: cmTC_38e6c \n    : && /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/ CMakeFiles/cmTC_38e6c.dir/testCXXCompiler.cxx.o  -o cmTC_38e6c   && :\n    /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\n    /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'\n    //lib/x86_64-linux-gnu/libgpg-error.so.0: undefined reference to `__libc_single_threaded@GLIBC_2.32'\n    //lib/x86_64-linux-gnu/libgpg-error.so.0: undefined reference to `pthread_mutex_trylock@GLIBC_2.34'\n    clang: error: linker command failed with exit code 1 (use -v to see invocation)\n    ninja: build stopped: subcommand failed.\n\n\n\n\n  CMake will not be able to correctly generate this project.\nCall Stack (most recent call first):\n  CMakeLists.txt:3 (project)\n
Run Code Online (Sandbox Code Playgroud)\n

我已经安装了 clang 和其他使用sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev

\n

这是flutter doctor结果

\n
[\xe2\x9c\x93] Flutter (Channel stable, 3.0.0, on Ubuntu 22.04 LTS 5.15.0-27-generic,\n    locale en_US.UTF-8)\n[\xe2\x9c\x93] Android toolchain - develop for Android devices (Android SDK version\n    32.1.0-rc1)\n[\xe2\x9c\x97] Chrome - develop for the web (Cannot find Chrome executable at\n    google-chrome)\n    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.\n[\xe2\x9c\x93] Linux toolchain - develop for Linux desktop\n[\xe2\x9c\x93] Android Studio (version 2021.2)\n[\xe2\x9c\x93] Connected device (1 available)\n[\xe2\x9c\x93] HTTP Host Availability\n\n! Doctor found issues in 1 category.\n
Run Code Online (Sandbox Code Playgroud)\n

Mif*_*zak 4

感谢Pkrarakal,我遵循了他的建议,错误消失了。尝试以下步骤:

  • 移动到边缘通道,snap refresh flutter --edge
  • 跑步flutter upgrade
  • 删除构建目录rm -r build/
  • 再次运行应用程序flutter run -d linux