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.13k stars 27.47k forks source link

Not able to build linux application #115230

Closed sumitsharansatsangi closed 1 year ago

sumitsharansatsangi commented 1 year ago

I am trying to build Linux application using flutter, but received following error

CMake Error at /usr/share/cmake-3.24/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/sumit/StudioProjects/todo/build/linux/x64/debug/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/ninja cmTC_a9f51 && [1/2] Building CXX object CMakeFiles/cmTC_a9f51.dir/testCXXCompiler.cxx.o
    [2/2] Linking CXX executable cmTC_a9f51
    FAILED: cmTC_a9f51 
    : && /usr/bin/clang++   CMakeFiles/cmTC_a9f51.dir/testCXXCompiler.cxx.o -o cmTC_a9f51   && :
    /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.

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

Steps to Reproduce

flutter run -d linux

Logs

Logs ``` ``` ``` $flutter doctor -v [✓] Flutter (Channel stable, 3.3.8, on Parrot OS 5.1 (Electro Ara) 6.0.0-2parrot1-amd64, locale en_GB.UTF-8) • Flutter version 3.3.8 on channel stable at /home/sumit/softwares/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 52b3dc25f6 (4 days ago), 2022-11-09 12:09:26 +0800 • Engine revision 857bd6b74c • Dart version 2.18.4 • DevTools version 2.15.0 Checking Android licenses is taking an unexpectedly long time...[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /home/sumit/Android/Sdk • Platform android-33, build-tools 30.0.3 • ANDROID_HOME = /home/sumit/Android/Sdk/ • ANDROID_SDK_ROOT = /home/sumit/Android/Sdk • Java binary at: /home/sumit/softwares/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted. [✓] Chrome - develop for the web • CHROME_EXECUTABLE = /usr/bin/chromium [✓] Linux toolchain - develop for Linux desktop • Debian clang version 11.0.1-2 • cmake version 3.24.2 • ninja version 1.10.1 • pkg-config version 0.29.2 [✓] Android Studio (version 2021.3) • Android Studio at /home/sumit/softwares/android-studio • Flutter plugin version 71.0.3 • Dart plugin version 213.7433 • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) [✓] Connected device (2 available) • Linux (desktop) • linux • linux-x64 • Parrot OS 5.1 (Electro Ara) 6.0.0-2parrot1-amd64 • Chrome (web) • chrome • web-javascript • Chromium 107.0.5304.87 built on Debian 11.5, running on Debian parrot [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ```
sldsrg commented 1 year ago
/usr/bin/ld: cannot find -lstdc++: No such file or directory

can be fixed with

sudo apt install libstdc++-dev
huycozy commented 1 year ago

@sumitsharansatsangi Can you try installing the library that @sldsrg mentioned above and check if the issue is solved?

sumitsharansatsangi commented 1 year ago

@huycozy , @sldsrg , I have tried what you have said. It works, but not completely. Now I am facing a permission error as follows:

        ] [5/6] Install the project...
[  +31 ms] -- Install configuration: "Debug"
[   +2 ms] -- Installing: /usr/local/todo
[   +1 ms] CMake Error at cmake_install.cmake:66 (file):
[   +6 ms]   file INSTALL cannot copy file
[        ]   "/home/sumit/AndroidStudioProjects/todo/build/linux/x64/debug/intermediates_do_not_run/todo"
[        ]   to "/usr/local/todo": Permission denied.
[  +11 ms] FAILED: CMakeFiles/install.util 
[        ] cd /home/sumit/AndroidStudioProjects/todo/build/linux/x64/debug && /usr/bin/cmake -P cmake_install.cmake
[        ] ninja: build stopped: subcommand failed.
[  +47 ms] Building Linux application... (completed in 13.4s)

I run the following command to build. flutter run -v -d linux

sumitsharansatsangi commented 1 year ago

After flutter clean it works. Thanks for the help.

radzish commented 1 year ago

I suggest this to be re-opened. After my Ubuntu upgraded with (most likely newest version of clang) flutter build does not work anymore with same error.

[✓] Flutter (Channel stable, 3.3.8, on Ubuntu 22.04.1 LTS 5.15.0-53-generic, locale en_US.UTF-8)
    • Flutter version 3.3.8 on channel stable at /home/kernel/work/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (13 days ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

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

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 14.0.0-1ubuntu1
    • cmake version 3.22.1
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2)
    • IntelliJ at /home/kernel/work/common/idea
    • Flutter plugin version 71.0.5
    • Dart plugin version 222.4345.14

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.1 LTS 5.15.0-53-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.
radzish commented 1 year ago

I resolved it. Following command did not work:

sudo apt install libstdc++-dev

I was requested to specify package with version explicitly:

sudo apt install libstdc++-12-dev

This worked.

github-actions[bot] commented 1 year 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.