sony / flutter-elinux

Flutter tools for embedded Linux (eLinux)
BSD 3-Clause "New" or "Revised" License
431 stars 44 forks source link

Cross building for arm64 on x64 host issues #94

Closed toygg96 closed 2 years ago

toygg96 commented 2 years ago

Hi @HidenoriMatsubayashi ,

I followed the guide in https://github.com/sony/meta-flutter to cross build using Yocto sdk (Skipped Cross-building using bitbake section). Everything succeeded. Then, I ran "source /opt/poky/3.1.15/environment-setup-aarch64-poky-linux" , "export CC=${CLANGCC}" and "export CXX=${CLANGCXX}". After that, I tried to run "flutter-elinux build elinux --target-arch=arm64 \ --target-compiler-triple=aarch64-poky-linux --system-include-directories=/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu -v" in https://github.com/sony/flutter-elinux/wiki/Building-flutter-apps#case-2-use-yocto-sdk.

But it gave me the following errors: [ +96 ms] executing: [/opt/flutter-elinux/sample/build/elinux/arm64/release/] cmake -DCMAKE_BUILD_TYPE=Release -DFLUTTER_TARGET_BACKEND_TYPE=wayland -DFLUTTER_TARGET_PLATFORM_SYSROOT=/ -DFLUTTER_SYSTEM_INCLUDE_DIRECTORIES=/usr/aarch64-linux-gnu/include/c++/9/aarch6 4-linux-gnu -DCMAKE_C_COMPILER_TARGET=aarch64-poky-linux -DCMAKE_CXX_COMPILER_TARGET=aarch64-poky-linux /opt/flutter-elinux/sample/elinux [ +225 ms] -- Toolchain file defaulted to '/opt/poky/3.1.15/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfi g.cmake' -- The CXX compiler identification is Clang 10.0.1 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /opt/flutter-elinux/sample/build/elinux/arm64/release [ ] executing: [/opt/flutter-elinux/sample/build/elinux/arm64/release/] cmake --build . [ +821 ms] Scanning dependencies of target flutter_assemble [ 0%] Built target flutter_assemble Scanning dependencies of target flutter_wrapper_plugin [ 7%] Building CXX object flutter/CMakeFiles/flutter_wrapperplugin.dir/ephemeral/cpp client_wrapper/core_implementations.cc.o

                In file included from
                /opt/flutter-elinux/sample/elinux/flutter/ephemeral/cpp_clie
                nt_wrapper/core_implementations.cc:21:
                In file included from
                /opt/flutter-elinux/sample/elinux/flutter/ephemeral/cpp_clie
                nt_wrapper/include/flutter/engine_method_result.h:8:
                //lib/gcc-cross/aarch64-linux-gnu/9/../../../../include/c++/
                9/memory:121:25: error: cast from pointer to smaller type
                'uintptr_t' (aka 'unsigned int') loses information
                  const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                1 error generated.
                make[2]: ***
                [flutter/CMakeFiles/flutter_wrapper_plugin.dir/build.make:63
                :
                flutter/CMakeFiles/flutter_wrapper_plugin.dir/ephemeral/cpp_
                client_wrapper/core_implementations.cc.o] Error 1
                make[1]: *** [CMakeFiles/Makefile2:118:
                flutter/CMakeFiles/flutter_wrapper_plugin.dir/all] Error 2
                make: *** [Makefile:130: all] Error 2

[ +21 ms] Building an eLinux application with wayland backend in release mode for arm64 target... (completed in 1,833ms) [ ] "flutter elinux" took 2,504ms. [ +7 ms] Failed to cmake build: Scanning dependencies of target flutter_assemble [ 0%] Built target flutter_assemble Scanning dependencies of target flutter_wrapper_plugin [ 7%] Building CXX object

flutter/CMakeFiles/flutter_wrapper_plugin.dir/ephemeral/cpp_clientwrapper/core implementations.cc.o

       In file included from

/opt/flutter-elinux/sample/elinux/flutter/ephemeral/cpp_client_wrapper/core_impl ementations.cc:21: In file included from

/opt/flutter-elinux/sample/elinux/flutter/ephemeral/cpp_client_wrapper/include/f lutter/engine_method_result.h:8:

//lib/gcc-cross/aarch64-linux-gnu/9/../../../../include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information const auto intptr = reinterpret_cast(ptr); ^~~~~~~~~~ 1 error generated. make[2]: *** [flutter/CMakeFiles/flutter_wrapper_plugin.dir/build.make:63:

flutter/CMakeFiles/flutter_wrapper_plugin.dir/ephemeral/cpp_clientwrapper/core implementations.cc.o] Error 1 make[1]: [CMakeFiles/Makefile2:118: flutter/CMakeFiles/flutter_wrapper_plugin.dir/all] Error 2 make: [Makefile:130: all] Error 2 [ +9 ms] 0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3) 1 NativeBundle.build (package:flutter_elinux/elinux_build_target.dart:387:7)

2 ELinuxBuilder.buildBundle (package:flutter_elinux/elinux_builder.dart:135:7) 3 BuildPackageCommand.runCommand (package:flutter_elinux/commands/build.dart:121:5) 4 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1161:27) 5 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) 6 CommandRunner.runCommand (package:args/command_runner.dart:209:13) 7 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9) 8 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) 9 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5) 10 run.. (package:flutter_tools/runner.dart:62:9) 11 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) 12 main (package:flutter_elinux/executable.dart:83:3) [ +6 ms] ensureAnalyticsSent: 3ms [ +1 ms] Running shutdown hooks [ ] Shutdown hooks complete [ ] exiting with code 1 Additional information: OS: Ubuntu 20.04.4 LTS Followed the instructions in https://github.com/sony/flutter-embedded-linux/issues/4#issuecomment-1090157925 to disable the compiler test for C and C++, set the target architecture and swap the x86_64 and the ARM64 linker as the Yocto SDK is using the wrong linker. Regards, Toy
HidenoriMatsubayashi commented 2 years ago

How about the below?

$ source /opt/poky/3.1.15/environment-setup-aarch64-poky-linux
$ export CC=${CLANGCC}
$ export CXX=${CLANGCXX}
$ flutter-elinux build elinux --target-arch=arm64 --target-compiler-triple=aarch64-poky-linux
toygg96 commented 2 years ago

How about the below?

$ source /opt/poky/3.1.15/environment-setup-aarch64-poky-linux
$ export CC=${CLANGCC}
$ export CXX=${CLANGCXX}
$ flutter-elinux build elinux --target-arch=arm64 --target-compiler-triple=aarch64-poky-linux

Yes I did those.

HidenoriMatsubayashi commented 2 years ago

You used --system-include-directories=/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu -v option, right? Would you please update your comment(issue) with the command you tried and the error correctly?

toygg96 commented 2 years ago

Hi Matsubayashi,

Commands Run: $ source /opt/poky/3.1.15/environment-setup-aarch64-poky-linux $ export CC=${CLANGCC} $ export CXX=${CLANGCXX} $ flutter-elinux build elinux --target-arch=arm64 --target-compiler-triple=aarch64-poky-linux

Failed to cmake build: Scanning dependencies of target flutter_assemble [ 0%] Built target flutter_assemble Scanning dependencies of target flutter_wrapper_plugin [ 7%] Building CXX object flutter/CMakeFiles/flutter_wrapper_plugin.dir/ephemeral/cpp_clientwrapper/core implementations.cc.o

In file included from /opt/flutter-elinux/sample/elinux/flutter/ephemeral/cpp_client_wrapper/core_impl ementations.cc:16: //lib/gcc-cross/aarch64-linux-gnu/9/../../../../include/c++/9/cassert:43:10: fatal error: 'bits/c++config.h' file not found

include <bits/c++config.h>

     ^~~~~~~~~~~~~~~~~~

1 error generated. make[2]: [flutter/CMakeFiles/flutter_wrapper_plugin.dir/build.make:63: flutter/CMakeFiles/flutter_wrapper_plugin.dir/ephemeral/cpp_clientwrapper/core implementations.cc.o] Error 1 make[1]: [CMakeFiles/Makefile2:118: flutter/CMakeFiles/flutter_wrapper_plugin.dir/all] Error 2 make: *** [Makefile:130: all] Error 2

If I use the "--system-include-directories" option (https://github.com/sony/flutter-elinux/wiki/Building-flutter-apps#troubleshooting), it gives a different error.

Commands Run: $ source /opt/poky/3.1.15/environment-setup-aarch64-poky-linux $ export CC=${CLANGCC} $ export CXX=${CLANGCXX} $ flutter-elinux build elinux --target-arch=arm64 \ --target-compiler-triple=aarch64-poky-linux --system-include-directories=/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu -v

Failed to cmake build: Scanning dependencies of target flutter_assemble [ 0%] Built target flutter_assemble Scanning dependencies of target flutter_wrapper_plugin [ 7%] Building CXX object

flutter/CMakeFiles/flutter_wrapper_plugin.dir/ephemeral/cpp_clientwrapper/core implementations.cc.o

       In file included from

/opt/flutter-elinux/sample/elinux/flutter/ephemeral/cpp_client_wrapper/core_impl ementations.cc:21: In file included from

/opt/flutter-elinux/sample/elinux/flutter/ephemeral/cpp_client_wrapper/include/f lutter/engine_method_result.h:8:

//lib/gcc-cross/aarch64-linux-gnu/9/../../../../include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information const auto intptr = reinterpret_cast(ptr); ^~~~~~~~~~ 1 error generated. make[2]: *** [flutter/CMakeFiles/flutter_wrapper_plugin.dir/build.make:63:

flutter/CMakeFiles/flutter_wrapper_plugin.dir/ephemeral/cpp_clientwrapper/core implementations.cc.o] Error 1 make[1]: [CMakeFiles/Makefile2:118: flutter/CMakeFiles/flutter_wrapper_plugin.dir/all] Error 2 make: [Makefile:130: all] Error 2 [ +5 ms]

0 throwToolExit

(package:flutter_tools/src/base/common.dart:10:3)

1 NativeBundle.build

       (package:flutter_elinux/elinux_build_target.dart:387:7)
       <asynchronous suspension>
       #2      ELinuxBuilder.buildBundle
       (package:flutter_elinux/elinux_builder.dart:135:7)
       <asynchronous suspension>
       #3      BuildPackageCommand.runCommand
       (package:flutter_elinux/commands/build.dart:121:5)
       <asynchronous suspension>
       #4      FlutterCommand.run.<anonymous closure>
       (package:flutter_tools/src/runner/flutter_command.dart:1161:27)
       <asynchronous suspension>
       #5      AppContext.run.<anonymous closure>
       (package:flutter_tools/src/base/context.dart:150:19)
       <asynchronous suspension>
       #6      CommandRunner.runCommand

(package:args/command_runner.dart:209:13)

#7 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9) #8 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) #9 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5) #10 run.. (package:flutter_tools/runner.dart:62:9) #11 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) #12 main (package:flutter_elinux/executable.dart:83:3)
HidenoriMatsubayashi commented 2 years ago

Could you use --target-sysroot option? I successed the build using its option.

$ sudo mv /opt/poky/3.1.16/sysroots/x86_64-pokysdk-linux/usr/bin/ld /opt/poky/3.1.16/sysroots/x86_64-pokysdk-linux/usr/bin/ld.x86_64
$ sudo cp -a /opt/poky/3.1.16/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld /opt/poky/3.1.16/sysroots/x86_64-pokysdk-linux/usr/bin/ld
$ source /opt/poky/3.1.15/environment-setup-aarch64-poky-linux
$ export CC=${CLANGCC}
$ export CXX=${CLANGCXX}
$ flutter-elinux build elinux --target-arch=arm64 --target-compiler-triple=aarch64-poky-linux --target-sysroot=/opt/poky/3.1.16/sysroots/aarch64-poky-linux
HidenoriMatsubayashi commented 2 years ago

Also, I updated Case 2: Use Yocto SDK.

HidenoriMatsubayashi commented 2 years ago

I'll close this issue, but please let me know if you have still any problems.

toygg96 commented 2 years ago

Hi Matsubayashi,

This command "flutter-elinux build elinux --target-arch=arm64 --target-compiler-triple=aarch64-poky-linux --target-sysroot=/opt/poky/3.1.16/sysroots/aarch64-poky-linux" works.

It is strange that I tried that command before and it didn't work with the exact same steps. Probably now it works because my Poky version is now 3.1.16?

Anyways, Thanks for your help :)

HidenoriMatsubayashi commented 2 years ago

It sounds nice. You're welcome.