隨筆 交叉編譯libcurl庫支援HTTPS

2021-08-26 12:14:51 字數 2666 閱讀 1720

2023年09月03日 10:19:43 閱讀數:2752 標籤: 交叉編譯

庫 更多

個人分類: 交叉編譯庫

提取碼:h29q

需要的編譯結果:mips下的libcurl庫支援https

關鍵:libcurl庫支援https協議,需要先編譯安裝openssl庫

配置環境變數 sudo vim /etc/profile

最後一行新增以下內容:

path=/usr/local/arm/4.4.3/bin:$path

執行source /etc/profile

echo $path

多了一條自己新增的mips交叉編譯工具鏈

/usr/local/mips/tool_chain/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
mipsel-linux-uclibc-gcc -v

檢視系統配置的編譯工具

交叉編譯libcurl時,直接執行./configure

如上圖,看第五行,ssl support為no看最後一行,支援的協議中沒有https,由此可知,我們編譯出來的curl庫並不支援https協議。

方案一:

./configure –with-ssl (加上ssl引數,因為預設./configure時沒帶該引數,所以導致編出來的curl庫不支援https)

如下圖,協議支援https,ssl support 為enabled

解決了curl庫支援https的問題,因為交叉編譯的curl庫需為mips平台的,命令./configure –with-ssl 交叉編譯的庫預設為x86平台。所以,我們加了引數,–host=mipsel-linux cc=tool_chain/bin/mipsel-linux-uclibc-gcc 。

那麼,問題就來了

./configure –with-ssl –host=mipsel-linux cc=/usr/local/mips/tool_chain/bin/mipsel-linux-uclibc-gcc 一套完整的命令敲下去後,curl庫為mips平台的,但是卻又不支援https了(應該是我的openssl庫為x86的,導致openssl和libcurl庫不相容)。

怎麼辦呢?看configure配置檔案,如下圖

–with-ssl有個預設的尋找ssl路徑 。

方案二:

先編譯安裝openssl庫,然後再編譯curl庫。

編譯openssl庫,

第一步:

--cross-compile-prefix=/usr/local/mips/tool_chain/bin/mipsel-linux-uclibc- --prefix=/usr/local/ssl no-asm shared
–cross-compile-prefix為交叉編譯工具鏈,–prefix為指定的安裝目錄。注意指定的目錄為/usr/local/ssl,同上面curl庫的–with-ssl引數default路徑,no-asm為在交叉編譯過程中不使用彙編**加速編譯過程,shared生成動態鏈結庫

第二步:

然後修改makefile

platform=mips

configure_args=mips

-m64相關的去掉(x86機器會有)

第三步:

make

make install

安裝完成後,我們去libcurl庫完成交叉編譯。

./configure --with-ssl=/usr/local/ssl --host=mipsel-linux cc=/usr/local/mips/tool_chain/bin/mipsel-linux-uclibc-gcc
make時可能會有以下錯誤:

checking for 「/dev/urandom」… configure: error: cannot check for file existence when cross compiling

交叉編譯時加上以下引數即可。

--with-random=/dev/urandom
最後完整的交叉編譯libcurl庫命令為:

./configure --with-ssl=/usr/local/ssl --host=mipsel-linux cc=/usr/local/mips/tool_chain/bin/mipsel-linux-uclibc-gcc --with-random=/dev/urandom
最終結果如下:

libcurl交叉編譯方法

1 cd curl 7.66.0 2 configure prefix home curl enable static cc arm gcc host linux 3 export lc all c,這個不一定需要,我的編譯鏈比較特殊才需要 4 make 5 make install 1 方法中的第...

交叉編譯支援https的libcurl

編譯curl 檢視效果 參考ubuntu 16.04.7 mips linux config cross compile prefix home gaoyang work cx compiles mips mips gcc520 32bit bin mips linux gnu prefix hom...

Linux下libcurl的編譯和交叉編譯

若是從github上直接clone下來的工程,則需要對工程做如下操作 aclocal autoconf autoheader automake add missing 若執行automake add missing時遇到 required file ltmain.sh not found 進行lib...