flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.2k stars 27.5k forks source link

Invalid toolchain leads to CMake error when compiling, flutter doctor does not detect this #144510

Open Diogenesoftoronto opened 8 months ago

Diogenesoftoronto commented 8 months ago

Steps to reproduce

Three simple steps to reproduce my problems.

flutter create [project name] flutter run 2 (for linux)

Expected results

This should open a gtk3 app with the basics running.

Actual results

I get this output instead:

Connected devices:
Linux (desktop) • linux  • linux-x64      • Pop!_OS
22.04 LTS 6.6.10-76060610-generic
Chrome (web)    • chrome • web-javascript • Google
Chrome 122.0.6261.94
[1]: Linux (linux)
[2]: Chrome (chrome)
Please choose one (or "q" to quit): 1

Launching lib/main.dart on Linux in debug mode...
Building Linux application...
Building Linux application...                          CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
Building Linux application...                            The C++ compiler
Building Linux application...                              "/usr/bin/clang++"
Building Linux application...                            is not able to compile a simple test program.
Building Linux application...
Building Linux application...                            It fails with the following output:
Building Linux application...                              Change Dir: /home/[redacted]/Programs/[redacted]/app/build/linux/x64/debug/CMakeFiles/CMakeTmp
Building Linux application...
Building Linux application...                              Run Build Command(s):/usr/bin/ninja cmTC_09ee2 && [1/2] Building CXX object CMakeFiles/cmTC_09ee2.dir/testCXXCompiler.cxx.o
Building Linux application...                              [2/2] Linking CXX executable cmTC_09ee2
Building Linux application...                              FAILED: cmTC_09ee2
Building Linux application...                              : && /usr/bin/clang++   CMakeFiles/cmTC_09ee2.dir/testCXXCompiler.cxx.o -o cmTC_09ee2   && :
Building Linux application...                              /usr/bin/ld: cannot find -lstdc++: No such file or directory
Building Linux application...                              clang: error: linker command failed with exit code 1 (use -v to see invocation)
Building Linux application...                              ninja: build stopped: subcommand failed.

Building Linux application...                            CMake will not be able to correctly generate this project.
Building Linux application...                          Call Stack (most recent call first):
Building Linux application...                            CMakeLists.txt:3 (project)
Error: Unable to generate build files

I changed nothing in my dart file from the initial project created by flutter create.

Code sample

Code sample ```dart [Paste your code here] ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console [Paste your logs here] ```

Flutter Doctor output

Doctor output ```console
huycozy commented 8 months ago

Hi @Diogenesoftoronto Looks like it's missing libstdc++ library on your system, please try installing it with below command:

sudo apt-get install libstdc++-12-dev

(See https://docs.flutter.dev/get-started/install/linux#additional-linux-requirements)

Diogenesoftoronto commented 8 months ago

Hey so, my code no longer breaks now, however I am not completely sure what step fixed it. I basically killed the project then started a new one and it worked.

huycozy commented 8 months ago

Glad to know the issue is no longer there. Since it is still vague for steps to reproduce, I'm going to close this. Once you face the issue again, please write in comments and I will reopen this for further investigation.

github-actions[bot] commented 7 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

christopherfujino commented 4 months ago

So I'm hitting this on my machine, with a brand new flutter create'd counter app:

Launching lib/main.dart on Linux in debug mode...
CMake Error at /usr/share/cmake-3.28/Modules/CMakeTestCXXCompiler.cmake:60 (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/fujino/git/tmp/delete_me_flutter/build/linux/x64/debug/CMakeFiles/CMakeScratch/TryCompile-rF7zK2'

    Run Build Command(s): /home/fujino/git/depot_tools/ninja -v cmTC_2db9d
    [1/2] /usr/bin/clang++    -MD -MT CMakeFiles/cmTC_2db9d.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_2db9d.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_2db9d.dir/testCXXCompiler.cxx.o -c /home/fujino/git/tmp/delete_me_flutter/build/linux/x64/debug/CMakeFiles/CMakeScratch/TryCompile-rF7zK2/testCXXCompiler.cxx
    [2/2] : && /usr/bin/clang++   CMakeFiles/cmTC_2db9d.dir/testCXXCompiler.cxx.o -o cmTC_2db9d   && :
    FAILED: cmTC_2db9d
    : && /usr/bin/clang++   CMakeFiles/cmTC_2db9d.dir/testCXXCompiler.cxx.o -o cmTC_2db9d   && :
    /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.

My flutter doctor:

~/git/tmp/delete_me_flutter$ flutter doctor -v
[✓] Flutter (Channel master, 3.23.0-13.0.pre.258, on Debian GNU/Linux rodete
    6.6.15-2rodete2-amd64, locale en_US.UTF-8)
    • Flutter version 3.23.0-13.0.pre.258 on channel master at
      /home/fujino/git/flutter
    • Upstream repository git@github.com:flutter/flutter.git
    • Framework revision cf375f0dfb (4 minutes ago), 2024-06-17 15:10:21 -0700
    • Engine revision a4f266f7eb
    • Dart version 3.5.0 (build 3.5.0-270.0.dev)
    • DevTools version 2.36.0

[✓] Android toolchain - develop for Android devices (Android SDK version
    33.0.0)
    • Android SDK at /home/fujino/Android/Sdk
    • Platform android-34, build-tools 33.0.0
    • Java binary at: /home/fujino/Downloads/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Debian clang version 16.0.6 (20)
    • cmake version 3.28.3
    • ninja version 1.11.1
    • pkg-config version 1.8.1

[✓] Android Studio (version 2022.2)
    • Android Studio at /home/fujino/Downloads/android-studio
    • Flutter plugin version 73.0.2
    • Dart plugin version 222.4582
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.87.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.80.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Debian GNU/Linux rodete
      6.6.15-2rodete2-amd64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 126.0.6478.61

[✓] Network resources
    • All expected network resources are available.

• No issues found!
christopherfujino commented 4 months ago

Here's the output of ldconfig -p:

~/git/fmr$ ldconfig -p | grep stdc
        libstdc++.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstdc++.so.6
        libstdc++.so.6 (libc6) => /lib32/libstdc++.so.6

When I first hit this, I did not have libstdc++-12-dev installed, however now I do and I'm still hitting this (could it be linker caching?):

$ sudo apt-get install libstdc++-12-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libstdc++-12-dev is already the newest version (12.3.0-14).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
viseztrance commented 1 month ago

Same problem on ubuntu 24.04. Installing libstdc++-12-dev doesn't help.

LATER EDIT - installing libstdc++-14-dev solved it.

robert-ancell commented 1 month ago

Summarizing the above - build was failing due to an incomplete toolchain. Once missing toolchain packages installed, worked as expected.

The solution to this would be to improve flutter doctor to better detect a broken toolchain and indicate what might need fixing.