一.安装MSYS2
- 官网地址:MSYS2
- 64位选择x86_64版本,直接install就行
二. 在MSYS2中安装MinGW
- Update the package database and core system packages
pacman -Syu
pacman -Su
- 安装32位版本和64位版本的工具链
pacman -S mingw-w64-i686-gcc
pacman -S mingw-w64-x86_64-gcc
- install some others important
pacman -S base-devel
pacman -S vim
pacman -S nasm
pacman -S git
安装完成之后,在开始菜单的目录会出现:“MSYS2 MinGW x86”以及“MSYS2 MinGW x64”,可以gcc -v查看是否出现提示信息
三.下载x264
- videoLAN:VLC
- 解压到MSYS2安装目录的home目录下
四.build
- 打开MSYS2 MinGW x64 ,cd到上述home下x264所在目录
MINGW64 /home/x264-master/x264-master
$
- set configure ,需要build .dll出来
./configure --host=x86_64-w64-mingw32 --enable-shared --disable-cli
- make
make
编译完毕后,在x264所在目录会生成libx264-164.dll
五.VS2019创建一个x64的控制台工程
- 有关创建x86 or x64控制台工程的问题可参考:百度百科
- 将libx264-164.dll copy到此工程的工作目录下
六.将.dll->.lib
- 下载pexports-0.47-mingw32-bin.tar.xz
- 将pexports.exe 也copy到五中工作目录下
- 利用VS的命令行工具,执行:
pexports libx264-164.dll > libx264-164.def
LIB /machine:X64 /DEF:libx264-164.def
- 配置依赖库
在链接器:输入->附加依赖项中,添加libx264-164.lib
七. 测试库是否正确
#include <iostream>
#include <string>
#include "stdint.h"
#pragma comment(lib, "libx264-164.lib")
extern "C"
{
#include "x264.h"
#include "x264_config.h"
};
using namespace std;
int main(int argc, char **argv)
{
x264_param_t param;
x264_param_default(¶m);
cout << "hello,x264" << endl;
return 0;
}
output:
hello,x264
D:\VS2019\SourceCode\x264\hello_x264\x64\Debug\hello_x264.exe (进程 16888)已退出,代码为 0。
要在调试停止时自动关闭控制台,请启用“工具”->“选项”->“调试”->“调试停止时自动关闭控制台”。
按任意键关闭此窗口. . .
参考文章:
1. windows下编译64位x264
2.【X265】Win10环境编译x264 / x265,调用libx264 / libx265