クロスコンパイルには、アーキテクチャに依存するライブラリとヘッダーファイルが必要です。
dpkg --add-architecture armhf
とapt-get update
の後にpython3.5-devパッケージなどをインストールできるかどうかをテストすると(source.listに若干の変更を加えた場合)、基本的に結果が得られました。
python3.5-dev:armhf : Depends: python3.5:armhf (= 3.5.1-10) but it is not going to be installed
apt-get install python3.5:armhf
既存の提案は(まだ)のバイナリではない異なるアーキテクチャのためのライブラリと ヘッダの共同設置を可能とするが、see
、動作しないものです。
"フル"仮想マシンを必要としないソリューションの1つが、QEMUとchrootによって提供されています。 chrootに適したディレクトリは、debootstrap
コマンドで作成できます。作成後、schroot
はその環境にアクセスできます。次のコマンドで
代替<DIRECTORY>
と<USER>
:
apt-get install -y debootstrap qemu-user-static binfmt-support schroot
debootstrap --arch=armhf --foreign --include=gcc,g++,python3.5-dev xenial <DIRECTORY>
cp /usr/bin/qemu-arm-static <DIRECTORY>/usr/bin
chroot <DIRECTORY>
/debootstrap/debootstrap --second-stage
echo "deb http://ports.ubuntu.com/ubuntu-ports xenial universe" >> /etc/apt/sources.list
echo "deb http://ports.ubuntu.com/ubuntu-ports xenial multiverse" >> /etc/apt/sources.list
apt-get update
apt-get install -y cython cython3
exit
cat <<END > /etc/schroot/chroot.d/xenial-armhf
[xenial-armhf]
description=Ubuntu xenial armhf
type=directory
directory=/home/xenial-armhf
groups=sbuild,root
root-groups=sbuild,root
users=root,<USER>
END
環境は、(ユーザーがroot-に記載されているグループである必要があります
schroot -c chroot:xenial-armhf
とrootユーザーセッションのためによりアクセス可能であるべきグループ)、
schroot -c chroot:xenial-armhf -u root
これは、cythonモジュールをコンパイル交差することも可能である。
hello.pyx:
print("hello world")
は(オプション、メモ-fPIC
ためのchrootでpython3.5-config --cflags
とpython3.5-config --libs
)をコンパイル:
cython hello.pyx
arm-linux-gnueabihf-gcc --sysroot <DIRECTORY> -I/usr/include/python3.5m -I/usr/include/python3.5m -Wno-unused-result -Wsign-compare -g -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -c hello.c
arm-linux-gnueabihf-gcc --shared --sysroot <DIRECTORY> -lpython3.5m -lpthread -ldl -lutil -lm hello.o -o hello.so
モジュールをテストすることができる。
schroot -c chroot:xenial-armhf
python3
import hello
cythonベースのPythonモジュールをクロスコンパイルすることもできます。 setup.pyで
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import os
os.environ['CC'] = 'arm-linux-gnueabihf-gcc'
os.environ['LDSHARED'] = 'arm-linux-gnueabihf-gcc -shared'
sysroot_args=['--sysroot', '/path/to/xenial-armhf']
setup(cmdclass = {'build_ext': build_ext},
ext_modules= [ Extension("hello", ["hello.pyx"],
extra_compile_args=sysroot_args,
extra_link_args=sysroot_args) ])
簡単なhello world
モジュールの構築が可能でした。モジュールのファイル名が間違っていました。この場合はhello.cpython-35m-x86_64-linux-gnu.so
でした。hello.so
という名前に変更した後、インポートすることができました。
仮想マシンにUbuntu armhfをインストールする方が簡単かもしれません。 qemuはarmv7、https://wiki.ubuntu.com/Kernel/Dev/QemuARMVexpress –
JJをサポートするはずです。完全仮想マシンをインストールせずにこれを行うことはできますか? – osgx
armhfインストール(約200 MiB)を含むディレクトリを作成し、そのディレクトリ(またはschroot)にchrootすることができます。 [QEMU/Debootstrapアプローチ](https://wiki.debian.org/EmDebian/CrossDebootstrap#QEMU.2Fdebootstrap_approach) –