8

I am trying to cross-compile Python 3.6 for my Raspberry Pi based on the instructions on this post, which boil down to setup then env vars so we use the linaro toolchain:

export CC=arm-bcm2708hardfp-linux-gnueabi-gcc export LD=arm-bcm2708hardfp-linux-gnueabi-ld export CXX=arm-bcm2708hardfp-linux-gnueabi-g++ export CPP="arm-bcm2708hardfp-linux-gnueabi-g++ -E" export READELF=arm-bcm2708hardfp-linux-gnueabi-readelf export RANLIB=arm-bcm2708hardfp-linux-gnueabi-ranlib export AR=arm-bcm2708hardfp-linux-gnueabi-ar
echo ac_cv_file__dev_ptmx=no > ./config.site
echo ac_cv_file__dev_ptc=no >> ./config.site
CONFIG_SITE=config.site ./configure --prefix=/home/user/Downloads/Python-3.6.1 --enable-ipv6 --build=arm-unknown-linux-gnueabihf --host=arm-unknown-linux-gnueabihf
make -j4
make install

However, I am stuck at the configure command which exits with an error that says:

checking whether we are cross compiling... configure: error: in `/home/user/Downloads/Python-3.6.1':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

What am I doing wrong? My host machine is Fedora 25 x86_64 and my Raspberry PI is a model 3 B.

arielnmz
  • 221
  • 1
  • 2
  • 10

2 Answers2

2

The instructions posted in this github wiki did it for me:

CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ AR=arm-linux-gnueabihf-ar \
    RANLIB=arm-linux-gnueabihf-ranlib \
    ./configure --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf \
    --build=x86_64-linux-gnu --prefix=$HOME/rapsberry/depsBuild/python \
    --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
    ac_cv_have_long_long_format=yes --enable-shared
make HOSTPYTHON=$HOME/raspberry/depsBuild/pythonhost/python \
    BLDSHARED="arm-linux-gnueabihf-gcc -shared" CROSS-COMPILE=arm-linux-gnueabihf- \
    CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=arm-linux-gnueabihf

As you can see I intentionally left out the part about compiling PGen and also omitted the HOSTPGEN envvar, and the compilation finished correctly, all that was left to do was to make the altinstall target using a target prefix like so (I took this final step from this guide for cross-compiling python 2):

make altinstall HOSTPYTHON=$HOME/raspberry/depsBuild/pythonhost/python \
    BLDSHARED="arm-linux-gnueabihf-gcc -shared" CROSS-COMPILE=arm-linux-gnueabihf- \
    CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=arm-linux-gnueabihf \
    prefix=$HOME/Python-3.6-rpi/_install

And finally copy the contents of the _install dir into the target device (for me, the destination path was under /usr/).

arielnmz
  • 221
  • 1
  • 2
  • 10
-1

Given your example I would try from python source folder:

echo ac_cv_file__dev_ptmx=no > ./config.site
echo ac_cv_file__dev_ptc=no >> ./config.site
CONFIG_SITE=config.site ./configure --build=i386-linux --host=arm-bcm2708hardfp-linux-gnueabi --target=arm-bcm2708hardfp-linux-gnueabi

make
Nelstaar
  • 99
  • 2