ninja: error: ‘/opt/homebrew/Cellar/opensslxxx/xx/lib/libssl.dylib

复制代码
Run Build Command(s): /Applications/CLion.app/Contents/bin/ninja/mac/aarch64/ninja -v -j 14 MediaServer
ninja: error: '/opt/homebrew/Cellar/openssl@3/3.3.2/lib/libssl.dylib', needed by '/Users/xxx/CLionProjects/ZLMediaKit/release/darwin/Debug/MediaServer', missing and no known rule to make it 

解决方案

这个错误表明构建过程需要一个 OpenSSL 动态库 (libssl.dylib),但路径 /opt/homebrew/Cellar/openssl@3/3.3.2/lib/libssl.dylib 下的文件不存在。可能的原因包括:

1.OpenSSL 未安装或路径不正确。

2.项目构建时引用的 OpenSSL 版本与系统中实际的版本不匹配。

解决步骤

  1. 检查 OpenSSL 是否已安装
    运行以下命令检查 OpenSSL 版本:

    brew list openssl@3

如果未安装,可以安装:

复制代码
brew install openssl@3
  1. 验证路径是否正确

    如果文件不存在,请查找 OpenSSL 动态库的实际路径:

  2. 修复路径引用

如果 OpenSSL 已安装但路径不一致,您可以修改 CMake 配置文件或环境变量,确保构建过程找到正确的 OpenSSL 路径。

eg.

复制代码
build % brew list openssl@3
 
/opt/homebrew/Cellar/openssl@3/3.4.0/.bottle/etc/ (9 files)
/opt/homebrew/Cellar/openssl@3/3.4.0/bin/c_rehash
/opt/homebrew/Cellar/openssl@3/3.4.0/bin/openssl
/opt/homebrew/Cellar/openssl@3/3.4.0/include/openssl/ (141 files)
/opt/homebrew/Cellar/openssl@3/3.4.0/lib/libcrypto.3.dylib
/opt/homebrew/Cellar/openssl@3/3.4.0/lib/libssl.3.dylib
/opt/homebrew/Cellar/openssl@3/3.4.0/lib/cmake/ (2 files)
/opt/homebrew/Cellar/openssl@3/3.4.0/lib/engines-3/ (3 files)
/opt/homebrew/Cellar/openssl@3/3.4.0/lib/ossl-modules/legacy.dylib
/opt/homebrew/Cellar/openssl@3/3.4.0/lib/pkgconfig/ (3 files)
/opt/homebrew/Cellar/openssl@3/3.4.0/lib/ (4 other files)
/opt/homebrew/Cellar/openssl@3/3.4.0/sbom.spdx.json
/opt/homebrew/Cellar/openssl@3/3.4.0/share/doc/ (879 files)
/opt/homebrew/Cellar/openssl@3/3.4.0/share/man/ (6182 files) 
/opt/homebrew/Cellar/openssl@3/3.4.0

从输出来看,我的 OpenSSL 版本是 3.4.0,而项目的构建过程试图使用的是 3.3.2,这导致了路径不匹配问题。

解决办法

  1. 将 3.4.0 的动态库链接到期望的 3.3.2 目录下
  • 执行以下命令

    mkdir -p /opt/homebrew/Cellar/openssl@3/3.3.2/lib
    ln -sf /opt/homebrew/Cellar/openssl@3/3.4.0/lib/libssl.3.dylib /opt/homebrew/Cellar/openssl@3/3.3.2/lib/libssl.dylib
    ln -sf /opt/homebrew/Cellar/openssl@3/3.4.0/lib/libcrypto.3.dylib /opt/homebrew/Cellar/openssl@3/3.3.2/lib/libcrypto.dylib

  • 然后重新构建项目:

    cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build
    cmake --build build

  1. 更新 CMake 配置文件

更好的方法是显式地告诉 CMake 使用 3.4.0 的路径。

  • 修改 CMakeLists.txt,在项目的 CMakeLists.txt 文件中添加以下行:

set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl@3")

set(OPENSSL_LIBRARIES "/opt/homebrew/opt/openssl@3/lib")

set(OPENSSL_INCLUDE_DIR "/opt/homebrew/opt/openssl@3/include")

  • 重新生成构建文件

    rm -rf build
    cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build
    cmake --build build

  1. 设置环境变量

如果无法修改 CMakeLists.txt,可以设置环境变量,临时修复路径问题。

运行以下命令:

复制代码
export OPENSSL_ROOT_DIR=$(brew --prefix openssl@3)
export OPENSSL_LIBRARIES=$OPENSSL_ROOT_DIR/lib
export OPENSSL_INCLUDE_DIR=$OPENSSL_ROOT_DIR/include
  • 重新生成构建文件

    cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build
    cmake --build build

相关推荐
MSTcheng.3 分钟前
【C++进阶】继承(下)——挖掘继承深处的奥秘!
开发语言·c++
学困昇4 分钟前
Linux基础开发工具(上):从包管理到“进度条”项目实战,掌握 yum/vim/gcc 核心工具
linux·运维·开发语言·数据结构·c++·vim
ALex_zry14 分钟前
Rust语言基础分析与C++对比:系统编程的现代演进
java·c++·rust
Molesidy16 分钟前
【QT】【C++】基于QT的多线程分别管理GUI和运算任务
开发语言·c++·qt
Vanranrr27 分钟前
Python vs PowerShell:自动化 C++ 配置文件的两种实现方案
c++·python·自动化
先知后行。27 分钟前
QT项目学习(自用)
c++·qt
ULTRA??40 分钟前
Qt 中基于 QVector3D 实现的直线交点+法向量计算函数
c++·qt
2301_807997381 小时前
代码随想录-day55
数据结构·c++·算法
艾莉丝努力练剑1 小时前
【Linux基础开发工具 (五)】详解自动化构建:make / Makefile
linux·运维·服务器·c++·centos·自动化
SongYuLong的博客1 小时前
C++基于jsoncpp开源库json数据操作
开发语言·c++·json