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

相关推荐
快乐的划水a8 小时前
组合模式及优化
c++·设计模式·组合模式
星星火柴9369 小时前
关于“双指针法“的总结
数据结构·c++·笔记·学习·算法
艾莉丝努力练剑10 小时前
【洛谷刷题】用C语言和C++做一些入门题,练习洛谷IDE模式:分支机构(一)
c语言·开发语言·数据结构·c++·学习·算法
阿巴~阿巴~12 小时前
深入解析C++ STL链表(List)模拟实现
开发语言·c++·链表·stl·list
旺小仔.13 小时前
双指针和codetop复习
数据结构·c++·算法
jingfeng51413 小时前
C++ STL-string类底层实现
前端·c++·算法
郝学胜-神的一滴13 小时前
基于C++的词法分析器:使用正则表达式的实现
开发语言·c++·程序人生·正则表达式·stl
努力努力再努力wz14 小时前
【c++深入系列】:万字详解模版(下)
java·c++·redis
瓦特what?16 小时前
关于C++的#include的超超超详细讲解
java·开发语言·数据结构·c++·算法·信息可视化·数据挖掘
祁同伟.16 小时前
【C++】动态内存管理
开发语言·c++