いろいろ備忘録日記

主に .NET とか Go とか Flutter とか Python絡みのメモを公開しています。

Flutterメモ-44 (dartでクロスコンパイルが可能に)(v3.8, まだlinuxへのクロスコンパイルのみ)

概要

以下、自分用のメモです。忘れないうちにメモメモ。。。

Dart 3.8 でクロスコンパイル出来るようになったみたいですね。

medium.com

dart.dev

dart.dev

現状、ベースOSからLinux向けのバイナリ作成のみをサポートしているみたいです。つまり、Linux上でWindows向けのバイナリなどは作成出来ない。

試してみた

Windows側

$ dart --version
Dart SDK version: 3.8.1 (stable) (Wed May 28 00:47:25 2025 -0700) on "windows_x64"

$ dart create app
Creating app using template console...

  .gitignore
  analysis_options.yaml
  CHANGELOG.md
  pubspec.yaml
  README.md
  bin\app.dart
  lib\app.dart
  test\app_test.dart

Running pub get...
  Resolving dependencies...
  Downloading packages...
  Changed 49 dependencies!
  1 package has newer versions incompatible with dependency constraints.
  Try `dart pub outdated` for more information.

Created project app in app! In order to get started, run the following commands:

  cd app
  dart run

$ cd app
$ dart run
Building package executable...
Built app:app.
Hello world: 42!


#
# Linux向けのバイナリ作成
#
$ dart compile exe --target-os=linux --target-arch=x64 bin/app.dart
Generated: ~\app\bin\app.exe

#
# bin/app.exeを実行するとエラーダイアログが表示される
#

#
# WSL側(Ubuntu)にファイルを移動
#
$ mv bin/app.exe \\wsl$\Ubuntu-24.04\home\dev\tmp

#
# WSL側で見てみる
#
$ wsl -d Ubuntu-24.04
$ cd tmp
$ file ./app.exe
./app.exe: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, with debug_info, not stripped

#
# 実行できることを確認
#
$ ./app.exe
Hello world: 42!

Linux側

$ dart create app
Creating app using template console...

  .gitignore
  analysis_options.yaml
  CHANGELOG.md
  pubspec.yaml
  README.md
  bin/app.dart
  lib/app.dart
  test/app_test.dart

Running pub get...                     1.1s
  Resolving dependencies...
  Downloading packages...
  Changed 49 dependencies!
  1 package has newer versions incompatible with dependency constraints.
  Try `dart pub outdated` for more information.

Created project app in app! In order to get started, run the following commands:

  cd app
  dart run

#
# Windows用のバイナリが作成できるか試してみる
#
$ cd app
$ dart compile exe --target-os=windows --target-arch=x64 bin/app.dart
Unsupported target platform windows_x64.
Supported target platforms: linux_arm64, linux_x64

Unsupported target platform windows_x64.

Supported target platforms: linux_arm64, linux_x64

って表示されますね。

参考情報

flutter.dev

dart.dev


過去の記事については、以下のページからご参照下さい。

サンプルコードは、以下の場所で公開しています。