Search code examples
c++flutterdartcmakeclang++

Flutter linux build error: cmake cannot compile a simple test program


I've been developping my first flutter app using flutlab and have recently set things up in vscode. Everything works fine in the web emulator but when I try to run for linux I get the following error:

Launching lib/main.dart on Linux in debug mode...
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "/usr/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/user/Downloads/Code/app/build/linux/x64/debug/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/ninja cmTC_5004a && [1/2] Building CXX object CMakeFiles/cmTC_5004a.dir/testCXXCompiler.cxx.o
    [2/2] Linking CXX executable cmTC_5004a
    FAILED: cmTC_5004a 
    : && /usr/bin/clang++   CMakeFiles/cmTC_5004a.dir/testCXXCompiler.cxx.o -o cmTC_5004a   && :
    /usr/bin/ld: cannot find -lstdc++: No such file or directory
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.
5

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

Error: Unable to generate build files

Exited (1).

Here's some additional info:

System:

Operating System: Kubuntu 22.04 KDE Plasma Version: 5.24.7 KDE Frameworks Version: 5.98.0 Qt Version: 5.15.3 Kernel Version: 5.15.0-100-generic (64-bit) Graphics Platform: X11

VScode:

Version: 1.87.1 Commit: 1e790d77f81672c49be070e04474901747115651 Date: 2024-03-06T00:21:07.287Z Electron: 27.3.2 ElectronBuildId: 26836302 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Linux x64 5.15.0-100-generic

Flutter:

Flutter 3.19.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision ba39319843 (2 days ago) • 2024-03-07 15:22:21 -0600 Engine • revision 2e4ba9c6fb Tools • Dart 3.3.1 • DevTools 2.31.1

Dart:

Dart SDK version: 3.3.1 (stable) (Wed Mar 6 13:09:19 2024 +0000) on "linux_x64"

cmake version 3.22.1

I've tried:

Purging and reinstalling clang --> nothing changed

Attempting to manually add the path --> can't find the right on in the myriad of search results in my file explorer, i have of course checked that libstdc++6 is installed along with the usual build-essential and g++

Now I'm not very well versed in c++ or cmake so I've been doing my best to troubleshoot but if anyone knows how to fix this it would be a lifesaver. If there's anything else you need to know, please ask.


Solution

  • The build configuration is telling the compiler to use the GNU standard C++ library from GCC.

    Install it

    sudo apt install libstdc++-dev