Flutter-desktop-embedding: [linux] Compile failure including standard library headers

Created on 30 Aug 2019  ·  14Comments  ·  Source: google/flutter-desktop-embedding

Describe the bug

$ pwd
/home/denizzz/Dev/flutter-desktop-embedding/example

$ flutter run
Launching lib/main.dart on Linux in debug mode...
Must specify package names on the command line                          
Must specify package names on the command line                          
In file included from flutter_embedder_example.cc:14:                   
flutter//cpp_client_wrapper_glfw/include/flutter/flutter_window_controller.h:10:10: fatal error: 'chrono' file not found
#include <chrono>                                                       
         ^                                                              
1 error generated.                                                      
In file included from flutter//cpp_client_wrapper_glfw/flutter_window_controller.cc:5:
flutter//cpp_client_wrapper_glfw/include/flutter/flutter_window_controller.h:10:10: fatal error: 'chrono' file not found
#include <chrono>                                                       
         ^                                                              
1 error generated.                                                      
In file included from flutter//cpp_client_wrapper_glfw/plugin_registrar.cc:5:
flutter//cpp_client_wrapper_glfw/include/flutter/plugin_registrar.h:8:10: fatal error: 'memory' file not found
#include <memory>                                                       
         ^                                                              
1 error generated.                                                      
In file included from flutter//cpp_client_wrapper_glfw/engine_method_result.cc:5:
flutter//cpp_client_wrapper_glfw/include/flutter/engine_method_result.h:8:10: fatal error: 'memory' file not found
#include <memory>                                                       
         ^                                                              
1 error generated.                                                      
make: *** [/home/denizzz/Dev/flutter-desktop-embedding/example/linux/../build/linux/debug/flutter_desktop_example] Ошибка 1
Building Linux application...                                           
Build process failed

Doctor Output
Please provide the output of flutter doctor -v:

[✓] Flutter (Channel master, v1.9.8-pre.23, on Linux, locale ru_RU.UTF-8)
    • Flutter version 1.9.8-pre.23 at /home/denizzz/Dev/flutter
    • Framework revision d5c5ac62ad (7 часов назад), 2019-08-29 21:52:33 -0700
    • Engine revision 9a17d8e451
    • Dart version 2.5.0 (build 2.5.0-dev.3.0 35382f9b14)


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /home/denizzz/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /home/denizzz/Dev/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Linux toolchain - develop for Linux desktop
    • clang++ 3.8.1
    • GNU Make 4.1

[✓] Android Studio (version 3.5)
    • Android Studio at /home/denizzz/Dev/android-studio
    • Flutter plugin version 38.2.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (1 available)
    • Linux • Linux • linux-x64 • Linux

• No issues found!
$ flutter analyze
Analyzing example...                                                    

   info • Unused import: 'package:flutter/services.dart' • lib/main.dart:18:8 • unused_import
   info • Prefer declare const constructors on `@immutable` classes • lib/main.dart:43:3 • prefer_const_constructors_in_immutables

2 issues found. (ran in 1.7s; 4 public members lack documentation)

Most helpful comment

I encountered this issue on Linux Mint 19.1.

$ clang -v
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Candidate multilib: .;@m64
Selected multilib: .;@m64

My solution is

sudo apt install libstdc++-8-dev

The gcc-multilib package is not necessary.

All 14 comments

That indicates that you either don't have the standard library, or it's not in your toolchain's include path. How did you install clang, and what distribution+version of Linux are you using?

I am on Debian. clang installed from repository.

$ clang --version
clang version 3.8.1-24 (tags/RELEASE_381/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$dpkg -l |grep clang
ii  clang                                                            1:3.8-36                                   amd64        C, C++ and Objective-C compiler (LLVM based)
ii  clang-3.5                                                        1:3.5-10                                   amd64        C, C++ and Objective-C compiler (LLVM based)
ii  clang-3.6                                                        1:3.6.2-3                                  amd64        C, C++ and Objective-C compiler (LLVM based)
ii  clang-3.8                                                        1:3.8.1-24                                 amd64        C, C++ and Objective-C compiler (LLVM based)
ii  clang-3.9                                                        1:3.9.1-9                                  amd64        C, C++ and Objective-C compiler (LLVM based)
ii  libclang-10-dev                                                  1:10~svn366440-1~exp1                      amd64        Clang library - Development package
ii  libclang-7-dev                                                   1:7.0.1-8                                  amd64        Clang library - Development package
ii  libclang-common-10-dev                                           1:10~svn366440-1~exp1                      amd64        Clang library - Common development package
ii  libclang-common-3.4-dev                                          1:3.4.2-13                                 amd64        clang library - Common development package
ii  libclang-common-3.5-dev                                          1:3.5-10                                   amd64        clang library - Common development package
ii  libclang-common-3.6-dev                                          1:3.6.2-3                                  amd64        clang library - Common development package
ii  libclang-common-3.8-dev                                          1:3.8.1-24                                 amd64        clang library - Common development package
ii  libclang-common-3.9-dev                                          1:3.9.1-9                                  amd64        clang library - Common development package
ii  libclang-common-7-dev                                            1:7.0.1-8                                  amd64        Clang library - Common development package
ii  libclang-cpp1-10                                                 1:10~svn366440-1~exp1                      amd64        C++ interface to the Clang library
ii  libclang-dev                                                     1:7.0-47.1                                 amd64        clang library - Development package
ii  libclang1:amd64                                                  1:7.0-47.1                                 amd64        C, C++ and Objective-C compiler (LLVM based)
ii  libclang1-10                                                     1:10~svn366440-1~exp1                      amd64        C interface to the Clang library
ii  libclang1-3.4:amd64                                              1:3.4.2-13                                 amd64        C interface to the clang library
ii  libclang1-3.5:amd64                                              1:3.5-10                                   amd64        C interface to the clang library
ii  libclang1-3.6:amd64                                              1:3.6.2-3                                  amd64        C interface to the clang library
ii  libclang1-3.8:amd64                                              1:3.8.1-24                                 amd64        C interface to the clang library
ii  libclang1-3.9:amd64                                              1:3.9.1-9                                  amd64        C interface to the clang library
ii  libclang1-7                                                      1:7.0.1-8                                  amd64        C interface to the Clang library

Also I tried to find chrono header, and looks like it is available on my system:

$ dpkg -S /usr/include/boost/chrono.hpp
libboost1.67-dev:amd64: /usr/include/boost/chrono.hpp
$ locate chrono\.h
/usr/include/boost/chrono.hpp
/usr/include/boost/asio/detail/chrono.hpp
/usr/include/boost/chrono/chrono.hpp
/usr/include/boost/chrono/detail/inlined/chrono.hpp
/usr/include/boost/chrono/detail/inlined/mac/chrono.hpp
/usr/include/boost/chrono/detail/inlined/posix/chrono.hpp
/usr/include/boost/chrono/detail/inlined/win/chrono.hpp
/usr/include/boost/chrono/typeof/boost/chrono/chrono.hpp
/usr/share/doc/autoconf-archive/html/ax_005fboost_005fchrono.html

That's Boost, not the standard library; this project doesn't use Boost. What does:

dpkg -S chrono | grep libstdc++

show? And failing that:

dpkg -l | grep libstdc++

As far as I can tell the clang package depends on a version (depending on your Debian version) of libstdc++ so I don't know why you wouldn't have it if you installed clang via the package manager. For instance, https://packages.debian.org/stretch/clang-3.8 depends on libstdc++-6-dev. (It would also be very strange for you to have Boost installed, but not the standard library.)

dpkg -S chrono | grep libstdc++

dpkg -S chrono | grep libstdc++
libstdc++-5-dev:amd64: /usr/include/c++/5/experimental/chrono
libstdc++-9-dev:amd64: /usr/include/c++/9/chrono
libstdc++-5-dev:amd64: /usr/include/c++/5/chrono
libstdc++-4.9-dev:amd64: /usr/include/c++/4.9/chrono
libstdc++-8-dev:amd64: /usr/include/c++/8/chrono
libstdc++-9-dev:amd64: /usr/include/c++/9/experimental/chrono
libstdc++-6-dev:amd64: /usr/include/c++/6/experimental/chrono
libstdc++-8-dev:amd64: /usr/include/c++/8/experimental/chrono
libstdc++-6-dev:amd64: /usr/include/c++/6/chrono
libstdc++-4.8-dev:amd64: /usr/include/c++/4.8/chrono

dpkg -l | grep libstdc++

dpkg -l | grep libstdc++
ii  libstdc++-4.8-dev:amd64                                          4.8.4-1                                    amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++-4.9-dev:amd64                                          4.9.3-14                                   amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++-5-dev:amd64                                            5.5.0-12                                   amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++-6-dev:amd64                                            6.3.0-18+deb9u1                            amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++-8-dev:amd64                                            8.3.0-19                                   amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++-9-dev:amd64                                            9.1.0-10                                   amd64        GNU Standard C++ Library v3 (development files)
rc  libstdc++5:amd64                                                 1:3.3.6-25                                 amd64        The GNU Standard C++ Library v3
ii  libstdc++6:amd64                                                 9.1.0-10                                   amd64        GNU Standard C++ Library v3
ii  libstdc++6:i386                                                  9.1.0-10                                   i386         GNU Standard C++ Library v3
rc  libstdc++6-armhf-cross                                           5.1.1-6cross1                              all          GNU Standard C++ Library v3

(It would also be very strange for you to have Boost installed, but not the standard library.)

Don't remember, but maybe it was necessary for another software build.

I have an idea, but I am not sure. Perhaps there in /usr/include/c++/ should be alternatives links to one of these headers? I.e., something like /usr/include/c++/chrono -> /usr/include/c++/9/chrono

I don't see any links like that in a working Debian-based setup. However, clang++ -v on a test C++ file suggests that it's finding the standard library through GCC-based paths, so it may be that for some reason it's not configured to use the paths that the dependent packages are installing into.

Does installing the g++ package resolve this? If so, I can update the instructions.

Does installing the g++ package resolve this?

Already installed. I am updated it from unstable repository without any positive result, flutter run returns same lines.

I'm afraid I'm not sure what else to suggest; it seems like your clang installation isn't correctly configured to compile C++ projects, but I'm not sure why that would be the case. You may want to try a more general resource like Stack Overflow (there's nothing unusual or Flutter-specific about this; #include <memory> is pretty basic for C++ compilation) and see if someone more familiar with edge cases in Linux C++ toolchain setups has more suggestions.

If you do find a solution I'd be interested to know what ends up working, to see if it's something we could detect and suggest a fix for in doctor.

You may want to try a more general resource like Stack Overflow (there's nothing unusual or Flutter-specific about this; #include is pretty basic for C++ compilation) and see if someone more familiar with edge cases in Linux C++ toolchain setups has more suggestions.

Ok

Some more information: this is how clang command displayed in flutter run -v:

[        ] clang++  -std=c++14 -Wall -Werror  -Iflutter/ -Iflutter//cpp_client_wrapper_glfw/include  flutter_embedder_example.cc flutter//cpp_client_wrapper_glfw/flutter_window_controller.cc
flutter//cpp_client_wrapper_glfw/plugin_registrar.cc flutter//cpp_client_wrapper_glfw/engine_method_result.cc -L/home/denizzz/Dev/flutter-desktop-embedding/example/linux/../build/linux/debug/lib -lflutter_linux_glfw
-Wl,-rpath=\$ORIGIN/lib -o /home/denizzz/Dev/flutter-desktop-embedding/example/linux/../build/linux/debug/flutter_desktop_example

No one -I options for /usr/include/c++. What is responsible for filling out these options?

Full output

$ flutter run -v
[  +26 ms] executing: [/home/denizzz/Dev/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +43 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] c4d54743b14a82d7a0b4dbe90ad9abfb3fa33cb2
[        ] executing: [/home/denizzz/Dev/flutter/] git describe --match v*.*.* --first-parent --long --tags
[  +23 ms] Exit code 0 from: git describe --match v*.*.* --first-parent --long --tags
[        ] v1.9.7-38-gc4d54743b
[  +12 ms] executing: [/home/denizzz/Dev/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[   +7 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/master
[        ] executing: [/home/denizzz/Dev/flutter/] git ls-remote --get-url origin
[   +5 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +53 ms] executing: [/home/denizzz/Dev/flutter/] git rev-parse --abbrev-ref HEAD
[   +7 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] master
[  +94 ms] executing: /home/denizzz/Android/Sdk/platform-tools/adb devices -l
[   +9 ms] Exit code 0 from: /home/denizzz/Android/Sdk/platform-tools/adb devices -l
[        ] List of devices attached
[  +40 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[ +152 ms] Launching lib/main.dart on Linux in debug mode...
[  +39 ms] Building Linux application...
[   +5 ms] make: Entering directory '/home/denizzz/Dev/flutter-desktop-embedding/example/linux'
[        ] /home/denizzz/Dev/flutter/packages/flutter_tools/bin/tool_backend.sh linux-x64 debug
[+9611 ms] Must specify package names on the command line
[   +2 ms] Must specify package names on the command line
[        ] mkdir -p /home/denizzz/Dev/flutter-desktop-embedding/example/linux/../build/linux/debug
[        ] clang++  -std=c++14 -Wall -Werror  -Iflutter/ -Iflutter//cpp_client_wrapper_glfw/include  flutter_embedder_example.cc flutter//cpp_client_wrapper_glfw/flutter_window_controller.cc
flutter//cpp_client_wrapper_glfw/plugin_registrar.cc flutter//cpp_client_wrapper_glfw/engine_method_result.cc -L/home/denizzz/Dev/flutter-desktop-embedding/example/linux/../build/linux/debug/lib -lflutter_linux_glfw
-Wl,-rpath=\$ORIGIN/lib -o /home/denizzz/Dev/flutter-desktop-embedding/example/linux/../build/linux/debug/flutter_desktop_example
[+1536 ms] In file included from flutter_embedder_example.cc:14:
[        ] flutter//cpp_client_wrapper_glfw/include/flutter/flutter_window_controller.h:10:10: fatal error: 'chrono' file not found
[        ] #include <chrono>
[        ]          ^
[   +6 ms] 1 error generated.
[  +22 ms] In file included from flutter//cpp_client_wrapper_glfw/flutter_window_controller.cc:5:
[        ] flutter//cpp_client_wrapper_glfw/include/flutter/flutter_window_controller.h:10:10: fatal error: 'chrono' file not found
[        ] #include <chrono>
[        ]          ^
[   +2 ms] 1 error generated.
[  +12 ms] In file included from flutter//cpp_client_wrapper_glfw/plugin_registrar.cc:5:
[        ] flutter//cpp_client_wrapper_glfw/include/flutter/plugin_registrar.h:8:10: fatal error: 'memory' file not found
[        ] #include <memory>
[        ]          ^
[   +9 ms] 1 error generated.
[  +16 ms] In file included from flutter//cpp_client_wrapper_glfw/engine_method_result.cc:5:
[        ] flutter//cpp_client_wrapper_glfw/include/flutter/engine_method_result.h:8:10: fatal error: 'memory' file not found
[        ] #include <memory>
[        ]          ^
[   +2 ms] 1 error generated.
[   +2 ms] Makefile:106: recipe for target '/home/denizzz/Dev/flutter-desktop-embedding/example/linux/../build/linux/debug/flutter_desktop_example' failed
[        ] make: Leaving directory '/home/denizzz/Dev/flutter-desktop-embedding/example/linux'
[        ] make: *** [/home/denizzz/Dev/flutter-desktop-embedding/example/linux/../build/linux/debug/flutter_desktop_example] Error 1
[  +18 ms] Building Linux application... (completed in 11.2s)
[   +3 ms] "flutter run" took 11,613ms.
Build process failed

#0      throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1      buildLinux (package:flutter_tools/src/linux/build_linux.dart:76:5)
<asynchronous suspension>
#2      LinuxDevice.startApp (package:flutter_tools/src/linux/linux_device.dart:83:13)
<asynchronous suspension>
#3      FlutterDevice.runHot (package:flutter_tools/src/resident_runner.dart:378:54)
<asynchronous suspension>
#4      HotRunner.run (package:flutter_tools/src/run_hot.dart:252:39)
<asynchronous suspension>
#5      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:460:37)
<asynchronous suspension>
#6      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:490:18)
#7      _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#8      _rootRunUnary (dart:async/zone.dart:1132:38)
#9      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#10     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#11     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#12     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#13     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#14     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#15     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#16     RunCommand.usageValues (package:flutter_tools/src/commands/run.dart)
#17     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#18     _rootRunUnary (dart:async/zone.dart:1132:38)
#19     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#20     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#21     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#22     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#23     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#24     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:552:7)
#25     _rootRun (dart:async/zone.dart:1124:13)
#26     _CustomZone.run (dart:async/zone.dart:1021:19)
#27     _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#28     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#29     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#30     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#31     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#32     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)

Dirty solution what works for me:

diff --git a/example/linux/Makefile b/example/linux/Makefile
index c72583e..2434414 100644
--- a/example/linux/Makefile
+++ b/example/linux/Makefile
@@ -76,7 +76,7 @@ SOURCES+=$(WRAPPER_SOURCES)

 # Headers
 WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include
-INCLUDE_DIRS=$(FLUTTER_APP_CACHE_DIR) $(WRAPPER_INCLUDE_DIR)
+INCLUDE_DIRS=$(FLUTTER_APP_CACHE_DIR) $(WRAPPER_INCLUDE_DIR) /usr/include/c++/9 /usr/include/x86_64-linux-gnu/c++/9

 # Build settings
 CXX=clang++ $(EXTRA_CXXFLAGS)

No, the problem was something else. Maybe gcc-multilib package was missing.

Now all builds works fine.

I encountered this issue on Linux Mint 19.1.

$ clang -v
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Candidate multilib: .;@m64
Selected multilib: .;@m64

My solution is

sudo apt install libstdc++-8-dev

The gcc-multilib package is not necessary.

In my case this package has already installed (if I'm not mistaken)

We need to determine exactly which packages are strictly needed.

I hit the same problem (my Linux distro is debian stretch) after having installed clang (via sudo apt-get install clang) and eventually ended up solving it by installing libstdc++-9-dev.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DavBfr picture DavBfr  ·  9Comments

rodydavis picture rodydavis  ·  6Comments

zhujintao picture zhujintao  ·  3Comments

stuartmorgan picture stuartmorgan  ·  10Comments

handicraftsman picture handicraftsman  ·  10Comments