0

My host is Ubuntu 20.04(x86_64) and my PC is Windows 10 Home (64-bit operating system, x64-based processor). I want to build a dart server to a single file. So, I used this command

dart compile exe dart_server/bin/dart_server.dart -o dart_server-linux-x64

to build the dart_server-linux-x64 file and move it to the host. and run this file by

./dart_server-linux-x64

Then I got the error:

-bash: ./dart_server-linux-x64: cannot execute binary file: Exec format error

How to solve that? I tried uploading the folder project(dart_server). Then run this dart server from this folder and it works successfully. But I want to use a single file, not the whole folder project. How to fix that?

  • 1
    I guess you compiled the binary on another OS platform than the target. That is not supported. If you want to run the binary on Linux, it must be compiled on Linux. – julemand101 Mar 16 '23 at 09:19
  • Is there any way to compile with cross-platform? – Sittiphan Sittisak Mar 16 '23 at 10:52
  • 2
    No, there are no way to cross-compile Dart code to a native executable that can be executed on all platforms. There are also, currently, not support for compiling a native executable for another platform than the one the compiler runs at. You can check the issue https://github.com/dart-lang/sdk/issues/28617 about that. – julemand101 Mar 16 '23 at 12:23
  • 1
    If you have Dart installed on your server, you can compile your program as `kernel` target which basically just bundles everything together into a single binary file. The binary cannot be executed directly but can be executed with the same Dart version but for different OS: https://dart.dev/tools/dart-compile#kernel – julemand101 Mar 16 '23 at 12:25
  • What is the exact OS and architecture of the server? – jamesdlin Mar 16 '23 at 15:23
  • My OS is Ubuntu 20.04.3 LTS (Focal Fossa) with kernel version 5.4.0-122-generic, and architecture x86_64 (64-bit). – Sittiphan Sittisak Mar 16 '23 at 15:37
  • What is the OS and architecture of the other machine? – jamesdlin Mar 16 '23 at 15:41
  • My com uses the Windows 10 Home (64-bit operating system, x64-based processor). – Sittiphan Sittisak Mar 16 '23 at 15:46
  • Ok, yeah, that won't work. Your question made it seem like both machines were running Linux. Perhaps you can use the Linux Dart SDK to compile in WSL. – jamesdlin Mar 16 '23 at 18:34
  • I added the detail in the post. Thank you for the answer. – Sittiphan Sittisak Mar 17 '23 at 00:12

0 Answers0