x264项目编译

Compilation of x264 project

本文关键字:编译 项目 x264      更新时间:2023-10-16

我已经下载了x264库的源代码。

x264的版本是148。

对于共享dll的编译,我使用以下命令MSYS环境:

./configure --disable-cli --enable-shared --prefix=.

结果如下:

platform:      X86_64
byte order:    little-endian
system:        WINDOWS
cli:           no
libx264:       internal
shared:        yes
static:        no
asm:           yes
interlaced:    yes
avs:           no
lavf:          no
ffms:          no
mp4:           no
gpl:           yes
thread:        win32
opencl:        yes
filters:       crop select_every
debug:         no
gprof:         no
strip:         no
PIC:           yes
bit depth:     8
chroma format: all

执行make后,我出现以下错误:

common/win32thread.o:win32thread.c:(.text+0x60): undefined reference to `_beginthreadex'
common/win32thread.o:win32thread.c:(.text+0x60): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_beginthreadex'
collect2: error: ld returned 1 exit status
Makefile:192: recipe for target 'libx264-148.dll' failed
make: *** [libx264-148.dll] Error 1

我的工作环境:

  1. Windows 10 Pro
  2. 带mingw64的MSYS64
  3. Microsoft Visual Studio 2015

configure命令执行时没有出现错误,但make给了我上述错误。

GCC由MSYS2/MinGW构建,具有不同的配置,并与不同版本的MinGW-w64头/libs捆绑在一起。

  • MSYS2仅提供posix线程模型(pthreads);i686为侏儒,x86_64为seh
  • MinGW提供posix和win32线程模型;i686的sjlj和dwarf,x86_64的seh和sjj

Ergo,MSYS应用程序需要使用pthreads库构建。您可以强制x264的MSYS构建使用posix线程模型,而不是像这样的win32模型:

$ ./configure --disable-cli --enable-shared --disable-win32thread

平台:X86_64
字节顺序:little-endian
系统:WINDOWS
cli:yes
libx264:内部
共享:yes
静态:否
asm:yes
隔行扫描:yes
avs:avisynth
lavf:no
ffms:no
mp4:no
gpl:yes
线程:posix
opencl:no
筛选器:crop select_every
lto:no
调试:no
gprof:noPIC:yes
位深度:all
色度格式:all

您现在可以运行"make"或"make fprofiled"。

问题是,没有msys/winpthreads包,因此您首先需要为MSYS2交叉编译pthreads-win32


说了这么多,你说

用于编译共享dll

而非

用于.so共享库的编译

所以这对我来说似乎是一个x-Y问题。我认为你应该使用MSYS来交叉编译x264,如下所示:

$ ./configure --host=x86_64-w64-mingw32 --disable-cli --enable-shared --cross-prefix=x86_64-w64-mingw32-

(为了与FFmpeg兼容,我也会使用--prefix=/usr/local--disable-opencl

./configure --enable-shared --enable-static --disable-thread

我也有同样的问题。它适用于禁用的线程。

我使用了以下选项:

./configure --disable-cli --enable-shared 

但我不想禁用线程,所以我修改了win32thread.c,如下所示:

之前:

#if HAVE_WINRT
/* _beginthreadex() is technically the correct option, but it's only available for Desktop applications.
* Using CreateThread() as an alternative works on Windows Store and Windows Phone 8.1+ as long as we're
* using a dynamically linked MSVCRT which happens to be a requirement for WinRT applications anyway */
#define _beginthreadex CreateThread
#define InitializeCriticalSectionAndSpinCount(a, b) InitializeCriticalSectionEx(a, b, CRITICAL_SECTION_NO_DEBUG_INFO)
#define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE)
#else
#include <process.h>
#endif

之后

#define _beginthreadex CreateThread
#if HAVE_WINRT
#define InitializeCriticalSectionAndSpinCount(a, b) InitializeCriticalSectionEx(a, b, CRITICAL_SECTION_NO_DEBUG_INFO)
#define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE)
#endif

基本上,我用Windows的原生CreateThread替换了_beginthreadex。不确定这对x264来说是个大问题,但现在我可以编译了。