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

相关推荐
Forget the Dream38 分钟前
设计模式之责任链模式
java·c++·设计模式·责任链模式
停止重构39 分钟前
【开源】低代码 C++程序框架,Linux多线程程序
c++·低代码·多线程·开源框架·云计算引擎
Duramentee42 分钟前
C++ 设计模式 十二:责任链模式 (读书 现代c++设计模式)
c++·设计模式·责任链模式
_GR1 小时前
Qt开发⑧Qt的窗口_下_浮动窗口+对话框
开发语言·css·c++·qt·microsoft
萌の鱼1 小时前
leetcode 3183. 达到总和的方法数量
数据结构·c++·算法·leetcode
Forget the Dream2 小时前
设计模式之代理模式
java·c++·设计模式·代理模式
攻城狮7号4 小时前
【第十节】C++设计模式(结构型模式)-Flyweight( 享元)模式
c++·设计模式·享元模式
Forget the Dream4 小时前
设计模式之享元模式
java·c++·设计模式·享元模式
溟洵8 小时前
【C/C++】理解C++内存与Linux虚拟地址空间的关系---带你通透C++中所有数据
linux·c语言·c++
Chandler2410 小时前
C++11 智能指针:unique_ptr、shared_ptr和weak_ptr 功能特性 模拟实现
开发语言·c++