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.

7
  • 1
    Is there any particular reason you need to do this rather than using the python36 package already available in Fedora 24 and newer?
    – mattdm
    Commented May 1, 2017 at 16:35
  • Well I wasn't aware that could be done, it would be great if you could detail the steps to do so in an answer please.
    – arielnmz
    Commented May 1, 2017 at 22:51
  • On the Pi, sudo dnf install python36
    – mattdm
    Commented May 1, 2017 at 23:30
  • 1
    This isn't a general answer, though, because it's much simpler than cross-compiling would be!
    – mattdm
    Commented May 1, 2017 at 23:31
  • 1
    you can't just sudo dnf on raspbian, for one, it's debian-based and uses aptitude, you are assuming I'm using fedora or even Pidora or FedBerry, I need to run python3.6 on Raspbian.
    – arielnmz
    Commented May 2, 2017 at 0:01

2 Answers 2

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/).

0
-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
3
  • I haven't tried but 1. can you elaborate as to why should the build param change from arm-unknown-linux-gnueabihf to i386-linux? 2. Should I use x86_64-linux or amd64-linux in case I'm on a 64-bit machine? 3. What is the difference between arm-unknown-linux-gnueabihf and arm-bcm2708hardfp-linux-gnueabi?
    – arielnmz
    Commented Jul 26, 2017 at 15:35
  • @arielnmz 1. --build parameter specify the platform you are building with so you shall set it accordingly. 2. x86_64-linux also worked for me 3. Here it's the prefix of your tool-chain you also need to set it accordingly
    – Nelstaar
    Commented Jul 28, 2017 at 15:17
  • I will try it asap, ty
    – arielnmz
    Commented Jul 28, 2017 at 15:33

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.