OBS Studio源码编译错误解决:常见问题与修复方案

OBS Studio源码编译错误解决:常见问题与修复方案

【免费下载链接】obs-studio 【免费下载链接】obs-studio 项目地址: https://gitcode.com/gh_mirrors/obs/obs-studio

OBS Studio(Open Broadcaster Software)是一款广泛使用的开源直播和录屏软件。在从源码编译OBS Studio时,开发者可能会遇到各种错误。本文将详细介绍常见的编译错误及其解决方案,帮助开发者顺利完成编译过程。

1. CMake版本不兼容问题

错误表现

CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.22 or higher is required.  You are running version 3.18.4

解决方案

OBS Studio要求CMake版本至少为3.22。可以通过以下命令安装最新版本的CMake:

# Ubuntu/Debian
sudo apt-get update
sudo apt-get install cmake -y

# 如果仓库中的版本仍然过低,可以使用Kitware的APT仓库
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt-get update
sudo apt-get install cmake -y

相关配置文件:CMakeLists.txt

2. 依赖项缺失问题

错误表现

CMake Error at cmake/Modules/FindLibObs.cmake:12 (find_package):
  Could not find a package configuration file provided by "LibObs" with any
  of the following names:
    LibObsConfig.cmake
    libobs-config.cmake

解决方案

OBS Studio有许多依赖项,不同操作系统的安装命令有所不同。

Ubuntu/Debian
sudo apt-get install -y \
  build-essential \
  checkinstall \
  cmake \
  git \
  libmbedtls-dev \
  libasound2-dev \
  libavcodec-dev \
  libavdevice-dev \
  libavfilter-dev \
  libavformat-dev \
  libavutil-dev \
  libcurl4-openssl-dev \
  libfontconfig1-dev \
  libfreetype6-dev \
  libgl1-mesa-dev \
  libjack-jackd2-dev \
  libjansson-dev \
  libluajit-5.1-dev \
  libpulse-dev \
  libqt5x11extras5-dev \
  libspeexdsp-dev \
  libswresample-dev \
  libswscale-dev \
  libudev-dev \
  libv4l-dev \
  libvlc-dev \
  libx11-dev \
  libx264-dev \
  libxcb-shm0-dev \
  libxcb-xinerama0-dev \
  libxcomposite-dev \
  libxinerama-dev \
  pkg-config \
  qtbase5-dev \
  qt5-qmake \
  qttools5-dev \
  qttools5-dev-tools \
  libqt5svg5-dev \
  libxkbcommon-x11-dev \
  libxcb-randr0-dev \
  libxcb-xfixes0-dev \
  libx11-xcb-dev \
  libxcb1-dev
Fedora
sudo dnf install -y \
  @development-tools \
  cmake \
  git \
  mbedtls-devel \
  alsa-lib-devel \
  ffmpeg-devel \
  libcurl-devel \
  fontconfig-devel \
  freetype-devel \
  mesa-libGL-devel \
  jack-audio-connection-kit-devel \
  jansson-devel \
  luajit-devel \
  pulseaudio-libs-devel \
  qt5-qtbase-devel \
  qt5-qtx11extras-devel \
  speexdsp-devel \
  systemd-devel \
  libv4l-devel \
  vlc-devel \
  libX11-devel \
  x264-devel \
  libxcb-devel \
  libXcomposite-devel \
  libXinerama-devel \
  qt5-linguist \
  qt5-qttools-devel \
  qt5-qtsvg-devel \
  libxkbcommon-x11-devel \
  xcb-util-randr-devel \
  xcb-util-xfixes-devel

相关配置文件:CMakeLists.txt

3. 编译器不支持C++17标准

错误表现

error: #error This file requires compiler and library support for the ISO C++ 2017 standard. This support must be enabled with the -std=c++17 or -std=gnu++17 compiler options.

解决方案

OBS Studio需要C++17或更高版本的支持。确保你的编译器支持C++17,并在编译选项中启用它。

# 检查GCC版本
gcc --version

# 如果GCC版本低于7.1,需要升级编译器
# Ubuntu/Debian
sudo apt-get install -y gcc-8 g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8

# 重新运行CMake,确保启用C++17
cmake -DCMAKE_CXX_STANDARD=17 ..
make -j4

相关配置文件:libobs/obs.hpp

4. Qt版本不匹配问题

错误表现

CMake Error at UI/CMakeLists.txt:10 (find_package):
  Could not find a configuration file for package "Qt5" that is compatible
  with requested version "5.15".

解决方案

OBS Studio需要Qt 5.15或更高版本。如果系统中安装的Qt版本过低,可以通过以下方式安装新版本:

Ubuntu/Debian
# 添加Qt官方仓库
sudo add-apt-repository ppa:beineri/opt-qt-5.15.2-focal
sudo apt-get update
sudo apt-get install -y qt515base qt515x11extras qt515svg qt515tools

# 设置环境变量
source /opt/qt515/bin/qt515-env.sh
源码编译Qt
git clone https://gitcode.com/qt/qt5.git -b 5.15.2 --recursive
cd qt5
./configure -opensource -confirm-license -prefix /usr/local/qt5
make -j4
sudo make install

相关配置文件:UI/CMakeLists.txt

5. 链接错误:未定义的引用

错误表现

libobs/libobs.so: undefined reference to `avcodec_send_frame@LIBAVCODEC_58'
collect2: error: ld returned 1 exit status

解决方案

这种错误通常是由于FFmpeg版本不兼容或链接不正确导致的。确保安装了正确版本的FFmpeg开发库。

Ubuntu/Debian
sudo apt-get install -y libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev
源码编译FFmpeg
git clone https://gitcode.com/FFmpeg/FFmpeg.git -b n4.4 --depth=1
cd FFmpeg
./configure --enable-shared --prefix=/usr/local/ffmpeg
make -j4
sudo make install

# 添加FFmpeg库路径
export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib:$LD_LIBRARY_PATH

相关配置文件:plugins/obs-ffmpeg/CMakeLists.txt

6. 构建系统弃用警告

错误表现

============ LEGACY BUILD SYSTEM IS DEPRECATED ============
You are using the legacy build system to build OBS Studio. The legacy build system is unsupported and will be removed in the near future.

解决方案

OBS Studio已弃用旧的构建系统,建议使用新的CMake Presets系统。

# 使用新的构建系统
cmake --preset linux-x86_64
cmake --build --preset linux-x86_64
sudo cmake --install build/linux-x86_64

相关配置文件:CMakePresets.json

7. 编译测试失败

错误表现

99% tests passed, 1 tests failed out of 100
Total Test time (real) =  45.23 sec
The following tests FAILED:
          1 - test-obs-source (Failed)
Errors while running CTest

解决方案

如果测试失败,可以选择暂时禁用测试构建,或者修复测试中发现的问题。

# 禁用测试构建
cmake -DBUILD_TESTS=OFF ..
make -j4

相关配置文件:test/CMakeLists.txt

总结

编译OBS Studio源码时遇到的错误大多与依赖项、编译器版本或构建配置有关。通过本文介绍的方法,应该能够解决大部分常见问题。如果遇到其他错误,建议查阅官方文档或在OBS Studio社区寻求帮助。

官方文档:INSTALL 官方仓库:https://gitcode.com/gh_mirrors/obs/obs-studio

【免费下载链接】obs-studio 【免费下载链接】obs-studio 项目地址: https://gitcode.com/gh_mirrors/obs/obs-studio

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值