0
votes

I write a simple encryption program with C for Raspberry Pi. It successfully compiled for my X86 CPU with gcc encoder.c -lcrypto -o encoder (I'd installed libssl-dev), but when I want to cross compile it (with arm-linux-gnueabihf-gcc), this error occur:

$ arm-linux-gnueabihf-gcc encoder.c -lcrypto -o encoder
    In file included from ./encoder.c:4:0:
    /usr/include/openssl/aes.h:55:33: fatal error: openssl/opensslconf.h: No such file or directory
    #include <openssl/opensslconf.h>
                                       ^
    compilation terminated.

How to cross compile an openssl C application for Raspberry Pi?

1
The easiest way is probably to SSH into the RPI and work directly form the device. The default credentials are username pi and password raspberry. Otherwise, you need to setup the shell enviroment for the cross-compile. You need to put tool chain and headers on path, and you need to set some variables like CROSS_COMPILE. Checkout the comments in the Configure script.jww
Thank you. as you proposed, I cann't install armhf packages directely into the x86 system. It is a similar problem & justification: superuser.com/questions/1080869/…SAP
You need direct access to the device for a native build or you need to cross-compile. If you can't SSH into the device and you can't cross-compile with the appropriate toolchain, then you can't build programs for the device.jww

1 Answers

0
votes

Your biggest problem is that your cross-compiler tries to use builds (as in your x86 machine) headers and it will also happily try to use wrong libraries if and when it comes to linking (and fail to link, of course). For a long time there is --sysroot option that solves exactly this problem, you just need to have properly set up sysroot for your target machine, and if you already have a cross-compiler chances are you do have some sysroot already. You just need to know proper paths (based on where and how you cross-compiler is installed), compile and install openssl itself (cross-compiling openssl in not fun, BTW) and then you'll be able to cross-compile something using openssl for your Pi.

As was already noted in the comments, building on the device is way easier, but Pi is slow, so there is a choice — easy setup and slow builds on Pi or relatively hard cross-compilation setup and fast builds on x86 machine.

As an alternative, you can try to use specialized cross-compiling build environments like OpenEmbedded, BuildRoot or OpenWRT, but that's also probably an overkill for one simple program.