交叉编译openssl C cpplication时出错

时间:2016-07-31 12:31:48

标签: openssl raspberry-pi cross-compiling

我用C for Raspberry Pi编写了一个简单的加密程序。它已成功为我的X86 CPU编译 gcc encoder.c -lcrypto -o encoder (我安装了libssl-dev),但当我想交叉编译它时(用arm-linux- gnueabihf-gcc),发生此错误:

$ 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.

如何为Raspberry Pi交叉编译openssl C应用程序?

1 个答案:

答案 0 :(得分:0)

你最大的问题是你的交叉编译器尝试使用构建(如在你的x86机器中)标题,如果涉及到链接(当然还有链接失败),它也会很乐意尝试使用错误的库。很长一段时间有--sysroot option解决了这个问题,你只需要为你的目标机器正确设置sysroot,如果你已经有了交叉编译器的机会,你确实已经有了一些sysroot。您只需要知道正确的路径(基于您安装交叉编译器的位置和方式),编译和安装openssl本身(交叉编译openssl并不好玩,BTW)然后您将能够使用交叉编译openssl for your Pi。

正如在评论中已经提到的那样,在设备上构建更容易,但是Pi很慢,所以有一个选择 - 简单的设置和慢速构建Pi或相对硬的交叉编译设置和快速构建x86机器。

作为替代方案,您可以尝试使用专门的交叉编译构建环境,如OpenEmbedded,BuildRoot或OpenWRT,但这对于一个简单程序来说也可能是一种过度杀伤。