x264 windows10下msys64下编译动态库

x264 windows10下msys64下编译动态库,并在Visual Studio 2019下调用简单例子:

1. 下载安装最新稳定版的 msys2

https://www.msys2.org/

https://repo.msys2.org/distrib/x86_64/

https://repo.msys2.org/distrib/x86_64/msys2-x86_64-20200720.exe

 

2. 下载安装最新稳定版的 mingw-w64:

https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/

https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z

https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-win32/seh/x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z

将其解压,覆盖msys2安装目录下的mingw64

 

3.更新系统包:

# Update the package database and core system packages(更新包数据库和核心包)
pacman -Syu

# normal msys2 packages
pacman -S make pkg-config diffutils cmake tar vim
# mingw-w64 packages and toolchains
# 下面这个是64位版本
pacman -S mingw-w64-x86_64-nasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2
# 下面这个是32位版本
# pacman -S mingw-w64-i686-nasm mingw-w64-i686-gcc mingw-w64-i686-SDL2
 

4. 安装Visual Studio 2019,并编写脚本msys_vs2019.cmd,放到msys2安装的根目录下:

set MSYS2_PATH_TYPE=inherit
#call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
msys2_shell.cmd -mingw64

4.下载x264的最新稳定版:

https://code.videolan.org/videolan/x264/-/tree/stable

 

5.解压并编译x264:

./configure --host=x86_64-w64-mingw64 --enable-static --enable-shared --enable-pic --enable-lto --extra-cflags="-O3 -fPIC" --extra-ldflags="-Wl,--output-def=libx264.def"

默认在/usr/local/bin生成dll和a文件

 

VS中有个LIB工具可以用来生成Lib文件libx264.lib:

32位版本LIB文件生成:

LIB /DEF:libx264.def /machine:x86

64位版本LIB文件生成:

LIB /DEF:libx264.def /machine:x64

 

6. 用VS做个简单的调用libx264的例子:

打开VS 创建一个空项目,并将x264.h, x264_config.h,libx264.lib,libx264.dll拷贝到项目中:

#include <stdio.h>
#include "stdint.h"

#pragma comment(lib,"libx264.lib")
extern "C"
{
#include "x264.h"
};

int main(void) {
    printf("libx264-version:%d\n", X264_BUILD);

    x264_param_t param;
    x264_param_default(&param);
    return 0;
}
编译生成.exe文件,将其和拷贝libx264.dll出来,在命令行中运行:

 

如果要生成静态库的话,要用64位的cl.exe编译生成libx264.lib:

CC=cl ./configure --host=x86_64-w64-mingw64 --enable-static --enable-shared --enable-pic --enable-lto --enable-strip --extra-cflags="-O3 -fPIC"

再就可以在上面的例子中调用libx264.lib

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章