Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when cross compiling Python for ARM

I'm trying to compile Python (version 3.1.3) for ARM, following this guide.

These are the commands I am issuing (on Ubuntu 12):

CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ AR=arm-linux-gnueabi-ar RANLIB=arm-linux-gnueabi-ranlib ./configure --host --build=x86_64-linux-gnu --prefix=/python

make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-linux-gnueabi- CROSS_COMPILE_TARGET=yes HOSTARCH=x86_64-linux-gnu BUILDARCH=x86_64-linux-gnu

make install HOSTPYTHON=./hostpython BLDSHARED="arm-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-linux-gnueabi- CROSS_COMPILE_TARGET=yes prefix=~/Python-2.7.2/_install

A few things to notice.

  1. When executing the first command, if --host is set to arm-linux, the command won't execute, telling me that I should use '--host' for cross-compiling. This is why I did not set it to anything.
  2. When running the second line, I get

configure: WARNING: Cache variable ac_cv_host contains a newline. Failed to configure _ctypes module

Python build finished, but the necessary bits to build these modules were not found: _curses _curses_panel _dbm
_gdbm _hashlib _sqlite3
_ssl bz2 ossaudiodev readline zlib To find the necessary bits, look in setup.py in detect_modules() for the module's name.

Failed to build these modules: _tkinter

I get a similar error when running the third line, but I guess it's due to the fact that the command above did not work.

I'm trying to see if anyone can help me fix it.

like image 814
Bob Avatar asked Dec 31 '13 20:12

Bob


1 Answers

It's much easier to compile natively under QEMU than cross-compile.

Unpack an arm chroot from whichever project you like, e.g. arch linux arm, raspbian, etc.

You already get binary python for arm, but if you really want to compile your own:

Download qemu-user-static (e.g. debian package), unpack that.

Install that single static binary into root of your arm chroot.

Add magic hex to binfmt in proc. Instructions for Debian, Gentoo, genric, List of magic hex sequences. Below are my settings:

mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
export QEMU_CPU=arm926

Optionally, mount --bind /tmp, /proc, /sys, as required.

Enjoy your virtual arm!

like image 171
Dima Tisnek Avatar answered Oct 09 '22 13:10

Dima Tisnek