如何在Linux 中修复“fatal error: x264.h: No such file or

提问: 我想在Linux中从源码编译视频编码程序。到那时,在编译时,我遇到了一个错误“fatal error: x264.h: No such file or directory”,我该如何修复?

下面的编译错误错明你系统中没有x264开发库文件。

  1. <span class="pln">fatal error</span><span class="pun">:</span><span class="pln"> x264</span><span class="pun">.</span><span class="pln">h</span><span class="pun">:</span><span class="typ">No</span><span class="pln"> such file </span><span class="kwd">or</span><span class="pln"> directory</span>

x264是GNU GPL授权的H.264/MPEG-4 AVC编码库。x264库被广泛用于视频编码/转码程序比如Avidemux、FFmpeg、 HandBrake、 OpenShot、 MEncode等等。

如何在Linux 中修复“fatal error: x264.h: No such file or

要解决这个问题,你需要安装x264的开发库文件。你可以如下做。

在 Debian、 Ubuntu 或者 Linux Mint 中安装像x264库和开发文件

在基于Debian的系统中,x264库已经包含在基础仓库中。可以直接用apt-get来安装。

  1. <span class="pln">$ sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install libx264</span><span class="pun">-</span><span class="pln">dev</span>

在 Fedora、 CentOS/RHEL中安装像x264库和开发文件

在基于Red Hat的发行版比如Fedora或者CentOS,x264库在免费的RPM Fusion仓库中有。那么,你需要首先安装RPM Fusion (免费) 。

RPM Fusion设置完成后,你可以使用下面的命令安装x264开发文件。

  1. <span class="pln">$ sudo yum </span><span class="pun">--</span><span class="pln">enablerepo</span><span class="pun">=</span><span class="pln">rpmfusion</span><span class="pun">-</span><span class="pln">free install x264</span><span class="pun">-</span><span class="pln">devel </span>

注意RPM Fusion仓库在CentOS 7中还没有,因此上面的方法在CentOS 7中还不可行。万一是CentOS 7 ,你可以从源码编译并安装x264,下面会解释的。

在Debian、 Ubuntu 或者 Linux Mint中源码编译x264库

如果libx264包在你的发行版中并没有,那么你可以按照下面的方法编译最新的x264库。

  1. <span class="pln">$ sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install g</span><span class="pun">++</span><span class="pln"> automake autoconf libtool yasm nasm git</span>
  2. <span class="pln">$ git clone git</span><span class="pun">:</span><span class="com">//git.videolan.org/x264.git</span>
  3. <span class="pln">$ cd x264</span>
  4. <span class="pln">$ </span><span class="pun">./</span><span class="pln">configure </span><span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="kwd">static</span><span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">shared</span>
  5. <span class="pln">$ make</span>
  6. <span class="pln">$ sudo make install </span>

x264库将会安装在/usr/local/lib。要让其他程序可以使用这个库,你需要完成最后一步。

打开/etc/ld.so.conf,并添加下面的行。

  1. <span class="pln">$ sudo vi </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">ld</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="pln">conf </span>

  1. <span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">lib</span>

最后运行下面的命令重新加载共享库:

  1. <span class="pln">$ sudo ldconfig</span>

在 Fedora, CentOS/RHEL 中源码编译x264库

如果你Linux的发行版中没有x264库(比如:CentOS 7)或者x264库并不是最新的,你可以如下编译最新的x264库。

  1. <span class="pln">$ sudo yum install gcc gcc</span><span class="pun">-</span><span class="pln">c</span><span class="pun">++</span><span class="pln"> automake autoconf libtool yasm nasm git</span>
  2. <span class="pln">$ git clone git</span><span class="pun">:</span><span class="com">//git.videolan.org/x264.git</span>
  3. <span class="pln">$ cd x264</span>
  4. <span class="pln">$ </span><span class="pun">./</span><span class="pln">configure </span><span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="kwd">static</span><span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">shared</span>
  5. <span class="pln">$ make</span>
  6. <span class="pln">$ sudo make install </span>

最后,要让其他的程序可以访问到位于 /usr/local/lib的x264库,在 /etc/ld.so.conf加入下面的行。

  1. <span class="pln">$ sudo vi </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">ld</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="pln">conf </span>

  1. <span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">lib</span>

最后运行下面的命令重新加载共享库:

  1. <span class="pln">$ sudo ldconfig </span>

如何在Linux 中修复“fatal error: x264.h: No such file or

相关推荐