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

相关推荐
程序猿编码10 小时前
基于 Linux 内核模块的字符设备 FIFO 驱动设计与实现解析(C/C++代码实现)
linux·c语言·c++·内核模块·fifo·字符设备
怎么没有名字注册了啊10 小时前
MFC_Install_Create
c++·mfc
Wadli11 小时前
C++语法 | static静态|单例模式
开发语言·c++·单例模式
进击的_鹏12 小时前
【C++11】initializer_list列表初始化、右值引用和移动语义、可变参数模版等
开发语言·c++
tongsound12 小时前
igh ethercat 实时性测试
linux·c++
睡不醒的kun12 小时前
leetcode算法刷题的第三十四天
数据结构·c++·算法·leetcode·职场和发展·贪心算法·动态规划
晚云与城12 小时前
今日分享:C++ deque与priority_queue
开发语言·c++
lingran__13 小时前
速通ACM省铜第四天 赋源码(G-C-D, Unlucky!)
c++·算法
Humbunklung14 小时前
unordered_map使用MFC的CString作为键值遇到C2056和C2064错误
c++·stl·mfc
爱编程的化学家15 小时前
代码随想录算法训练营第十一天--二叉树2 || 226.翻转二叉树 / 101.对称二叉树 / 104.二叉树的最大深度 / 111.二叉树的最小深度
数据结构·c++·算法·leetcode·二叉树·代码随想录