卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章64334本站已运行4115

openssl 错误 ld:警告:找不到选项 '-L/usr/local/opt/openssl/lib 的目录

openssl 错误 ld:警告:找不到选项 '-l/usr/local/opt/openssl/lib 的目录

php小编香蕉在使用openssl时遇到了一个错误,提示"ld:警告:找不到选项'-L/usr/local/opt/openssl/lib'的目录"。这个错误通常是由于openssl的库文件路径未正确配置所导致的。解决这个问题的方法是在编译选项中添加正确的openssl库文件路径。

问题内容

编译与 openssl 调用相关的 tdlib 程序时出现错误。

/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)

openssl 已随brew 安装:

which openssl
/opt/homebrew/bin/openssl
==> 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/[email protected]
License: Apache-2.0

我尝试使用 pkg-config 并暴露下一个环境来解决此问题,但没有任何帮助。

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

解决方法

你也可以检查这些标志吗(.~/bashrc 或 ~/.zshrc):

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

或者你可以使用pkg-config:

export CGO_CFLAGS="$(pkg-config --cflags openssl)"
export CGO_LDFLAGS="$(pkg-config --libs openssl)"
卓越飞翔博客
上一篇: golang:如何定义步骤序列
下一篇: 如何使用带有方法的字符串枚举作为泛型参数?
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏