0

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?

SAP
  • 5
  • 8
  • 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](http://github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/Configure). – jww Jul 31 '16 at 16:45
  • Thank you. as you proposed, I cann't install armhf packages directely into the x86 system. It is a similar problem & justification: http://superuser.com/questions/1080869/how-do-i-download-a-debian-arm-package-from-another-computer – SAP Aug 07 '16 at 08:39
  • 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 Aug 07 '16 at 18:04

1 Answers1

0

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.

Roman Khimov
  • 4,807
  • 1
  • 27
  • 35
  • You are absolutely right dear Roman Khimov. I solved this problem by transferring the necessary files into my PC along with the -L & -I. You propose a better solution. However, I have really confused. I can cross compile a simple c-code with out --sysroot option, due to the "libc6-dev-armel-cross" package. Why I can't use such a cross-package in this scenario? – SAP Aug 21 '16 at 14:00
  • @SAP: Maybe there is something I don't know about Debian cross-toolchains, never actually used any of that. Have a look [at this question](http://stackoverflow.com/questions/17603213/cross-compilation-gcc-ignores-sysroot), maybe it's close to your particular situation. – Roman Khimov Aug 21 '16 at 18:27