curl 的编译过程会用到openssl,所以在交叉编译 curl 之前,需要先交叉编译 openssl
https://blog.csdn.net/weixin_44023406/article/details/103610397
1、下载源码
https://curl.haxx.se/download.html
2、解压
解压:tar -xzvf curl-7.67.0.tar.gz
进入解压后目录:cd curl-7.67.0
3、配置
LIBS="-ldl -ssl -crypto" ./configure --host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g++ --with-ssl=/usr/local/openssl/arm_openssl --prefix=/usr/local/curl/arm_curl
CPPFLAGS="-I/usr/local/openssl/arm_openssl/include" LDFLAGS="-L/usr/local/openssl/arm_openssl/lib" LIBS="-ldl" ./configure --host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g++ --with-ssl --enable-shared --enable-static --disable-dict --disable-ftp --disable-imap --disable-ldap --disable-ldaps --disable-pop3 --disable-proxy --disable-rtsp --disable-smtp --disable-telnet --disable-tftp --disable-zlib --without-ca-bundle --without-gnutls --without-libidn --without-librtmp --without-libssh2 --without-nss --without-zlib --prefix=/usr/local/curl/arm_curl
CPPFLAGS="-I/usr/local/openssl/arm_openssl/include"
LDFLAGS="-L/usr/local/openssl/arm_openssl/lib"
LIBS="-ldl"
./configure
–host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g++
–with-ssl --enable-shared --enable-static --disable-dict --disable-ftp --disable-imap --disable-ldap --disable-ldaps --disable-pop3 --disable-proxy --disable-rtsp --disable-smtp --disable-telnet --disable-tftp --disable-zlib --without-ca-bundle --without-gnutls --without-libidn --without-librtmp --without-libssh2 --without-nss --without-zlib
–prefix=/usr/local/curl/arm_curl
这里为了讲解把指令拿出来并加了换行,实际使用时直接复制上面代码框里的指令即可
参数说明:
CPPFLAGS 设置 openssl 的头文件路径,注意引号、-I(大写 i )等细节
LDFLAGS 指定 openssl 的动态库或者静态库路径
这里交叉编译 curl 的话,openssl 也要使用交叉编译后的库,可参考:openssl 交叉编译
LIBS="-ldl" 指定需要链接的库的 名字(不包含 lib 和 .a 或 .so)请参考:gcc -I -i -L -l 参数区别 / -l(静态库/动态库)
–host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g++ 设置交叉编译工具
中间的一大段我也看不明白,希望大神能指点一下
–prefix=XXXXX 设置编译后的安装路径
上面一整段不要换行,放在终端里运行即可
(可以先放在记事本里,对应参数改成自己的,确认无误后复制到终端)
配置结果
遇到的错误1: 配置 openssl 的路径时缺少 -L、-I(大写 i )
解决:https://blog.csdn.net/weixin_44023406/article/details/103625445
错误2: openssl 相关函数找不到
解决:
4、编译
make
遇到的错误
解决:
5、安装
make install
目标文件夹下生成两个文件夹
lib 文件夹下,适用于 ARM 架构的动态库和静态库
软链接也没有问题
6、使用
在编译自己的代码的时候,把刚刚编译生成的静态库( libcurl.a
)路径引入即可,【 使用Makefile 的同学在 Makefile 中调用 】
可以把整个 arm_curl
文件夹复制到工程目录下,相对路径引用即可,直接复制过去不影响使用
curl 找不到的错误没有了,但是出现更多错误(鼠标滚轮一直翻不完的那种)
找不到 SSL
的相关函数、MD5
的相关函数、DES
的相关函数 等等
把 openssl 的静态库引入即可
另外,还有找不到pthread
的相关函数、 dlxxx
的相关函数、 rtxxx
的相关函数,同理,编译时引入即可
这三个在包含在 gcc 里面,不需要单独编译,手动引入项目
参考:
https://blog.csdn.net/andylauren/article/details/78821916