Quantumleap
352 words
2 minutes
x264をmacOSでビルドする
2024-01-11

背景#

Q. え、x264って普通にビルド済みのバイナリありますよね、なんで?

A. とある理由で機能を追加したバージョンが欲しかったから

手順#

おおまかな手順はこちらの通り。

git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --prefix=/usr/local --enable-pic --enable-shared
make

とはいえ、このコマンドだけでは上手くいきません。

makeの実行中にエラーが出てコケます。

コンパイラの変更#

macOSではデフォルトでclangが使われる設定になっているのでこれらをgcc, g++に変更します。

brew install gcc

シンボリックリンク#

以下の二つのコマンドで、インストールしたバイナリの名前がわかります。

GCC#

$ ls /opt/homebrew/bin | grep gcc                             
aarch64-apple-darwin23-gcc-13
aarch64-apple-darwin23-gcc-ar-13
aarch64-apple-darwin23-gcc-nm-13
aarch64-apple-darwin23-gcc-ranlib-13
gcc-13
gcc-ar-13
gcc-nm-13
gcc-ranlib-13

G++#

$ ls /opt/homebrew/bin | grep g++
aarch64-apple-darwin23-g++-13
g++-13

なのでシンボリックリンクを貼ります。

sudo ln -s /opt/homebrew/bin/g++-13 /usr/local/bin/g++
sudo ln -s /opt/homebrew/bin/gcc-13 /usr/local/bin/gcc 

これでターミナルを起動し直します。

確認#

$ gcc --version                                               
gcc (Homebrew GCC 13.2.0) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version
g++ (Homebrew GCC 13.2.0) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

どちらもHomebrewからインストールしたものが使われていることがわかります。

あとはこのままビルドすればエラーも発生せずに終了します。

記事は以上。

x264をmacOSでビルドする
https://fuwari.vercel.app/posts/2024/01/x264/
Author
tkgling
Published at
2024-01-11