ubuntu “/usr/bin/ld文件夹:找不到-lstdc++:运行flutter linux应用程序时没有这样的文件或目录”

kiz8lqtg  于 2022-11-28  发布在  Flutter
关注(0)|答案(1)|浏览(753)

在Linux桌面应用程序的flutter run上出现此错误

  1. Running "flutter pub get" in proj... 5.3s
  2. Launching lib/main.dart on Linux in debug mode...
  3. CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  4. The C++ compiler
  5. "/usr/bin/clang++"
  6. is not able to compile a simple test program.
  7. It fails with the following output:
  8. Change Dir: /media/kingbob/Dvolve/EData/proj/build/linux/x64/debug/CMakeFiles/CMakeTmp
  9. Run Build Command(s):/usr/bin/ninja cmTC_5f1b6 && [1/2] Building CXX object CMakeFiles/cmTC_5f1b6.dir/testCXXCompiler.cxx.o
  10. [2/2] Linking CXX executable cmTC_5f1b6
  11. FAILED: cmTC_5f1b6
  12. : && /usr/bin/clang++ CMakeFiles/cmTC_5f1b6.dir/testCXXCompiler.cxx.o -o cmTC_5f1b6 && :
  13. /usr/bin/ld: cannot find -lstdc++: No such file or directory
  14. clang: error: linker command failed with exit code 1 (use -v to see invocation)
  15. ninja: build stopped: subcommand failed.
  16. CMake will not be able to correctly generate this project.
  17. Call Stack (most recent call first):
  18. CMakeLists.txt:2 (project)
  19. Building Linux application...
  20. Exception: Unable to generate build files

Flutter刮刀输出

  1. Doctor summary (to see all details, run flutter doctor -v):
  2. [✓] Flutter (Channel stable, 3.3.8, on Ubuntu 22.04.1 LTS 5.15.0-53-generic, locale en_IN)
  3. [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
  4. [✓] Chrome - develop for the web
  5. [✓] Linux toolchain - develop for Linux desktop
  6. [✓] Android Studio (version 2021.3)
  7. [✓] Connected device (2 available)
  8. [✓] HTTP Host Availability
  9. No issues found!

clang++ --版本的输出

  1. Ubuntu clang version 14.0.0-1ubuntu1
  2. Target: x86_64-pc-linux-gnu
  3. Thread model: posix
  4. InstalledDir: /usr/bin

我注意到缺少/usr/lib/libstdc++.so,因此手动创建了一个符号链接sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/libstdc++.so
然后我在flutter run上结束了这个错误

  1. Launching lib/main.dart on Linux in debug mode...
  2. /usr/include/glib-2.0/glib/glib-typeof.h:39:10: fatal error: 'type_traits' file not found
  3. /usr/include/glib-2.0/glib/glib-typeof.h:39:10: fatal error: 'type_traits' file not found
  4. /usr/include/glib-2.0/glib/glib-typeof.h:39:10: fatal error: 'type_traits' file not found
  5. /usr/include/glib-2.0/glib/glib-typeof.h:39:10: fatal error: 'type_traits' file not found
  6. /usr/include/glib-2.0/glib/glib-typeof.h:39:10: fatal error: 'type_traits' file not found
  7. /usr/include/glib-2.0/glib/glib-typeof.h:39:10: fatal error: 'type_traits' file not found
f5emj3cl

f5emj3cl1#

原来是升级到clang-14导致了这个问题。下面是我解决这个问题的方法:

  • 降级到clang-13
  • 如果/usr/lib/libstdc++.so不存在,则创建符号链接。sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/libstdc++.so
  • 如果您正在flutter run上获取fatal error: 'type_traits' file not found,则导出clang包括路径export CPLUS_INCLUDE_PATH="${CPLUS_INCLUDE_PATH:+${CPLUS_INCLUDE_PATH}:}/usr/lib/llvm-13/include/c++/v1/"

相关问题