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

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