LoginSignup
0
2

More than 1 year has passed since last update.

binfmt + wine で Windows バイナリを Linux で ./a.exe のようにして実行するメモ

Last updated at Posted at 2020-05-09

背景

Wine で Windows バイナリを動かす時に, wine64 a.exe とか打つのがめんどい.
./a.exe とかで, .exe を直接実行したい.

binfmt でいけます.

方法

Ubuntu(systemd 系)だと, まずは systemd-binfmt.service を立ち上げておきます.

$ sudo systemctl start systemd-binfmt

binfmt 用の設定を /usr/share/binfmts に作ります.

Ubuntu apt だと, wine-binfmt パッケージがあります.
(ただ, これだと設定ファイルをインストールするだけのようで, 後述の update-binfmts はいずれにせよ必要だった)

/usr/share/binfmts/wine 設定ファイルを, 以下のように import して反映させます.

$ sudo update-binfmts --import wine

あとはこれで, windows バイナリを ./a.exe のようにして起動できます!

DLL path

MinGW や llvm-mingw(clang)だと, 何もしないとランタイム dll
(lib***.dll) が見つからないエラーが出るため, PATH or LD_LIBRARY_PATH.dll の場所を指定する必要があります.

アプリの構成によっては, 完全 static ビルドができるかもしれません.

msys2とC++で特定のDLLに依存しないwindowsバイナリを作る
https://siuncyclone.hatenablog.com/entry/2018/07/21/194629

llvm-mingw(libcxx, clang)の場合は

$ -static -lstdc++

でいけます.
(例外もうまく扱えているようですが, SEH の場合どうなるかは不明. 一応 libunwind, libcxx でサポートされているっぽい? https://reviews.llvm.org/D50564 )

binfmt とは?

The Linux binfmt subsystem
http://anadoxin.org/oldblog/linux-binfmt

バイナリのフォーマット(通常はヘッダ)を見て, どのようにプロセスを実行するかを切り替える機能になります.

いろいろ頑張ると, aarch64 バイナリを, ./aarch64.out で qemu + chroot で aarch64 システムで実行, みたいなのができます.

qemu + binfmt + chroot で AARCH64 環境を構築する.
https://syoyo.wordpress.com/2013/12/17/qemu-binfmt-chroot-%E3%81%A7-aarch64-%E7%92%B0%E5%A2%83%E3%82%92%E6%A7%8B%E7%AF%89%E3%81%99%E3%82%8B/

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2