Using cython to cross compile a project from Intel ubuntu to hand

I have a simple python + cython project (hello from the example http://docs.cython.org/src/tutorial/cython_tutorial.html ) on my ubuntu 16 x86_64. I can build this project using cython for x86_64.

How can I build a project for armv7 version of ubuntu 15 without using a real armp7 / cpu board?

I have arm-linux-gnueabihf-gcc( http://packages.ubuntu.com/xenial/devel/gcc-arm-linux-gnueabihf ) and it can compile simple C programs for armv7. How to change cython settings to use cross-compiler to create shared objects for the hand?

+4
source share
1 answer

Architecture-dependent libraries and header files are required for cross-compilation.

When testing, if the python3.5-dev package and others can be installed after dpkg --add-architecture armhfand apt-get update(after some modification in sources.list), the result was basically.

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- this is what does not work, see

Existing suggestions provide for the joint installation of libraries and headers for different architectures, but not (nevertheless) binary files.

One possible solution that does not require a “full” virtual machine is provided by QEMU and chroot. A suitable directory for chroot can be created by the team debootstrap. Once created, it schrootcan provide access to this environment.

<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

schroot -c chroot:xenial-armhf

root ( , ),

schroot -c chroot:xenial-armhf -u root

cython:

hello.pyx:

print("hello world")

(python3.5-config --cflags python3.5-config --libs chroot , -fPIC):

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

, - python- cython. 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, .

+4

All Articles