macOS 编译 openssl + libcurl

libcurl库 但是不支持 https 协议 现在加上openssl 来支持https

首先下载 openssl 源码https://www.openssl.org/source

我这边下载的是3.0.13

https://www.openssl.org/source/old/

编译openssl 参考这个https://zhuanlan.zhihu.com/p/628437266   

主要命令

./Configure darwin64-x86_64-cc --prefix="/Users/aa/Downloads/curl-openssl/openssl-x86_64" no-asm
sudo make
sudo make install
make clean
./Configure darwin64-arm64-cc --prefix="/Users/aa/Downloads/curl-openssl/openssl-arm64" no-asm
sudo make
sudo make install

下载页面 https://curl.se/download/

完成之后 编译libcurl

https://blog.csdn.net/qq_40218744/article/details/112307286

参考这个。 

./configure --disable-ldap --without-zlib --disable-ldaps --with-openssl="/Users/aa/Downloads/curl-openssl/openssl-x86_64" --prefix="/Users/aa/Downloads/curl-openssl/curl-x86_64" 
sudo make
sudo make install

./configure --disable-ldap --without-zlib --disable-ldaps --with-openssl="/Users/aa/Downloads/curl-openssl/openssl-arm64" --prefix="/Users/aa/Downloads/curl-openssl/curl-arm64" 
sudo make
sudo make install

遇到了几个坑 

configure: error: --with-openssl was given but OpenSSL could not be detected

根据错误信息,configure 脚本无法检测到 OpenSSL 库。这可能是由于路径错误或 OpenSSL 库本身的问题导致的。以下是解决问题的一些建议:

  1. 检查 OpenSSL 路径: 确保指定的 OpenSSL 路径是正确的,且包含了 OpenSSL 库文件。你可以通过在终端中执行以下命令来检查路径是否正确:

    ls /Users/aa/Downloads/curl-openssl/openssl-x86_64

    如果 OpenSSL 库的路径正确,应该能够看到 OpenSSL 库的文件列表。

  2. 检查 OpenSSL 库文件: 确保指定的 OpenSSL 路径中包含了正确的 OpenSSL 库文件。通常情况下,你应该能够在指定的路径下找到 libssl.so 或 libssl.dylib(取决于你的系统)以及 libcrypto.so 或 libcrypto.dylib 文件。

  3. 尝试使用其他方法指定 OpenSSL 路径: 有时候指定路径的方法可能不适用于所有的 configure 脚本。你可以尝试使用其他方法来指定 OpenSSL 路径,例如设置 PKG_CONFIG_PATH 环境变量来指定 pkg-config 文件的搜索路径,这样 configure 脚本就能够自动检测到 OpenSSL 了。

    export PKG_CONFIG_PATH=/Users/aa/Downloads/curl-openssl/openssl-x86_64/lib/pkgconfig

    然后再运行 configure 命令。

  4. 检查 OpenSSL 版本: 确保你下载的 OpenSSL 版本与 configure 脚本兼容。有些版本的 OpenSSL 可能与特定版本的 Curl 不兼容,导致 configure 脚本无法正确检测到 OpenSSL。

  5. 可能是因为我是arm平台 我要编译x86_64的原因

尝试以上方法后,如果问题仍然存在,请确保 OpenSSL 的路径和文件是正确的,并且与你的系统架构相匹配。

 
这边就是有些openssl版本跟curl不兼容 导致的。还有就是 我自己编译完改了路径 没有改里面的对应的pc文件的里面的路径
 
切换到x86_64 编译  可以使用 

如果想运行其他程序 可以使用 arch -x86_64 xxxx可执行文件

 同理 arch -arm64  zsh

以上虽然编译完了,也可以运行,但是移到别的电脑上是无效果的== 

最后把openssl打成静态库 

./Configure darwin64-arm64-cc --prefix="/Users/aa/Downloads/curl-openssl/openssl-arm64-static" no-asm no-shared 
就可以了== 

 

那这边就顺带复习下静态库和动态库 

 

posted @ 2024-03-28 11:17  冰糖葫芦很乖  阅读(41)  评论(0编辑  收藏  举报