Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross building for arm64 on x64 host issues #94

Closed
toygg96 opened this issue Apr 26, 2022 · 9 comments
Closed

Cross building for arm64 on x64 host issues #94

toygg96 opened this issue Apr 26, 2022 · 9 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@toygg96
Copy link

toygg96 commented Apr 26, 2022

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_wrapper_plugin.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_client_wrapper/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<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
[ +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 sony/flutter-embedded-linux#4 (comment) 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
Copy link
Collaborator

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
Copy link
Author

toygg96 commented Apr 26, 2022

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
Copy link
Collaborator

HidenoriMatsubayashi commented Apr 27, 2022

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
Copy link
Author

toygg96 commented Apr 27, 2022

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_client_wrapper/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_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

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_client_wrapper/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<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
[ +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)

#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)

@HidenoriMatsubayashi
Copy link
Collaborator

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
Copy link
Collaborator

Also, I updated Case 2: Use Yocto SDK.

@HidenoriMatsubayashi HidenoriMatsubayashi added documentation Improvements or additions to documentation question Further information is requested labels Apr 27, 2022
@HidenoriMatsubayashi
Copy link
Collaborator

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

@toygg96
Copy link
Author

toygg96 commented Apr 28, 2022

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
Copy link
Collaborator

It sounds nice. You're welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants