You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译TDLib程序遇OpenSSL链接错误,求解决方案

编译TDLib时遭遇OpenSSL链接错误

编译TDLib程序时出现OpenSSL相关的链接错误,具体报错信息如下:

/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib'
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)

已通过Homebrew安装OpenSSL@3,相关验证信息:
执行which openssl输出:

/opt/homebrew/bin/openssl

brew中openssl@3的安装详情:

==> openssl@3: stable 3.1.2 (bottled)
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/openssl@3/3.1.2 (6,495 files, 28.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-09-21 at 14:06:03
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/openssl@3.rb
License: Apache-2.0

曾尝试通过pkg-config设置CGO环境变量,但未解决问题:

export CGO_CFLAGS=$(pkg-config --cflags openssl)
export CGO_LDFLAGS=$(pkg-config --libs openssl)

解决方法

问题根源是Apple Silicon设备上Homebrew默认将OpenSSL安装在/opt/homebrew/opt/openssl@3,但链接器默认查找/usr/local/opt/openssl路径,且pkg-config未正确指向目标版本。可尝试以下方案:

  1. 直接指定OpenSSL实际路径
    替换原有环境变量设置,明确指向brew安装的openssl@3路径:

    export CGO_CFLAGS="-I/opt/homebrew/opt/openssl@3/include"
    export CGO_LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib -lssl -lcrypto"
    

    设置完成后重新编译TDLib。

  2. 让pkg-config正确识别openssl@3
    先配置pkg-config的查找路径,再重新设置CGO变量:

    export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"
    export CGO_CFLAGS=$(pkg-config --cflags openssl)
    export CGO_LDFLAGS=$(pkg-config --libs openssl)
    go build ./...
    
  3. 编译时临时指定链接路径
    若不想设置环境变量,可直接在编译命令中传递参数:

    go build -ldflags="-L/opt/homebrew/opt/openssl@3/lib" -tags="openssl" ./...
    

内容的提问来源于stack exchange,提问作者Vladyslav Martynenko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 06:40:59