9

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.

13
  • What embedded Linux distro are you using? If Python version is not important, you could just take Buildroot. It provides Python 3.3.
    – yegorich
    Commented Jan 1, 2014 at 0:59
  • I'm doing it as an exercise, CCing for busy-box
    – zzzbbx
    Commented Jan 5, 2014 at 0:42
  • 1
    Not an expert at this by any means, but the last time I had to do cross-compiling on ARM (for QNX OS) the ./configure step needed to specify --target and --host, I think. Does the --host error go away if you specify --target=arm-linux and --host=arm-linux?
    – user44484
    Commented Jan 9, 2014 at 3:35
  • 3
    It seems to me the the ARM compiler is not finding the header files neded to compile those extension modules (_curses, _ssl, bz2, etc). Or the libs couldn't be found... Those are not part of the compiler; so in any case you'll need to either build all those libs from source for ARM (and tell the python build where to find them) or configure python to skip those modules.
    – greggo
    Commented Jan 9, 2014 at 17:55
  • 3
    If I may suggest backtracking a bit, it is easier to natively compile in a running ARM system than it is to cross compile. To that end, I like to do ARM software builds in QEMU. Here is a quick start guide to doing that. xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way Commented Jan 11, 2014 at 8:24

2 Answers 2

1

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!

0

I got the same error and just ignored it and carried on with the procedure suggested by http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html

It worked with a hello_world program. You can also run a testall.py file from the _install/lib/Python2.7/ folder. You can also refer to http://whatschrisdoing.com/blog/talks/PyConTalk2012.pdf

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.