Home >Backend Development >Golang >openssl error ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib'

openssl error ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib'

王林
王林forward
2024-02-10 14:24:091094browse

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

php editor Banana encountered an error when using openssl, prompting "ld: warning: option '-L/usr/local/opt/openssl/lib' not found Table of contents". This error is usually caused by the openssl library file path being incorrectly configured. The solution to this problem is to add the correct openssl library file path in the compilation options.

Problem content

An error occurred while compiling the tdlib program related to openssl call.

/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 is installed with 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

I tried using pkg-config and exposing the next environment to resolve this issue, but nothing helped.

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

Workaround

Can you also check these flags (.~/bashrc or ~/.zshrc):

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

Or you can use pkg-config:

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

The above is the detailed content of openssl error ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib'. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete