msys2编译libx264库

本文详细介绍了如何使用msys2和mingw-w64工具链在Windows环境下从源码编译libx264库,并将其转换为可以在Visual Studio中使用的动态链接库(.dll)文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

时间已经是2018年了,又一次编译libx264的32/64位的库,写个笔记吧。同时也发在了新浪博客。
这次使用msys2原始安装包。下载地址:https://sourceforge.net/projects/msys2/

(1)双击安装msys2-x86_64-20161025.exe,默认安装路径
C:\msys64\mingw32.exe或mingw64.exe,分别是mingw的32和64位编译环境

(2)编译64位libx264库,就打开mingw64.exe安装gcc等基本的编译工具,
 参考链接
https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2


MSYS has not been updated a long time, MSYS2 is more active, you can download from MSYS2, it has both mingw and cygwin fork package.

To install the MinGW toolchain (Reference):

1.      Open MSYS2 shell from start menu

2.      Run pacman -Sy pacman to update the package database

3.      Re-open the shell, run pacman -Syu to update the package database and core system packages

4.      Re-open the shell, run pacman -Su to update the rest

5.      (Reference)

·         For 32-bits, run pacman -S mingw-w64-i686-toolchain

·         For 64 bits, run pacman -S mingw-w64-x86_64-toolchain

6.      Select which package to install, default is all

7.      You may also need make, run pacman -S make


 

没有安装编译环境之前, gcc -v  会提示找不到gcc,
安装工具链之后,gcc -v会显示gcc版本号

(3)解决libx264所需的依赖库,譬如缺少nasm

pacman -S nasm

(4)下载libx264源码,解压缩,进入x264源码的目录下
官方网站
https://www.videolan.org/developers/x264.html

git clone http://git.videolan.org/git/x264.git
(5)编译libx264,编译出.a并能够转为.lib,参考链接

http://www.ayobamiadewole.com/Blog/Others/x264compilation.aspx

Now compiling the x264 into a dynamic link library that can be used in Visual studio takes another process entirely. Open the MinGW bash once again and change the directory to the location of your x264 source code, just like you did previously. 
Then type 
./configure --disable-cli --enable-shared --extra-ldflags=-Wl,--output-def=libx264-120.def 
              or just 
./configure --disable-cli --enable-shared --extra-ldflags=-Wl,--output-def=libx264.def


 
  
Now in libx264-120.def “120” is the version of the x264 you are using, you can find the version of the x264 you are using by opening the x264.h file in your x264 source folder you will see something like this #define X264_BUILD 120 depending on your version.

You can now type the make command and press enter and you will find the libx264-120.dll in your x264 source folder. Then rename libx264-120.dll to libx264.dll and you have you dynamic link library to work with.

 

If you wish to generate the Visual Studio .lib file to work with then open a Visual Studio command prompt, and change the directory to the location of the x264 source . 
Then run this command
 LIB /DEF:libx264.def  /Machine:x64
Then press enter 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值