vlc3.0.4在ubuntu16.04x64上的交叉编译全过程记录

xiaoxiao2025-04-30  13

    周末折腾了好久,经过连续的出现问题,定位问题,解决问题,终于顺利编译通过了vlc的最新版本,中间尝试了多个版本的编译,比如vlc3.0.0,想着离2.x版本(2.x版本已经编译通过,可以参考:ubuntu平台,VLC/LibVLC交叉编译,生成win32版本,以及LibVLC增加录像接口)比较接近,应该容易编译通过,没成想也是一堆问题,其实主要还是版本导致的接口不对应问题,于是ubuntu的各种版本16.04x86,16.04x64,18.04x64等的尝试,终于看到了成功的果实,就像是中了大奖一样的心情。好吧,闲话不多说了,下面记录一下编译过程中的问题。

   编译环境是在win7系统的虚拟机里面安装的ubuntu16.04x64 LTS版本,这个没什么好说的,不熟的可以自行搜索。因为vlc3.x版本需要gcc/g++支持c++11,所以gcc/g++的版本不能太低,可以通过命令gcc --version查看一下,我用的是4.9.3版本,大于4.9.0的版本都支持c++11。

   官方的编译文档虽然说照着做肯定编译不过,但还是要参考一下的,最起码知道每一步该怎么去操作。

   一、Mingw-w64环境

因为vlc主要用的还是32位版本,所以直接安装x86交叉编译环境:

sudo apt-get install gcc-mingw-w64-i686 g++-mingw-w64-i686 mingw-w64-tools

二、开发工具集

vlc编译过程所依赖的相关工具等,直接命令安装即可。

sudo apt-get update sudo apt-get install lua5.2 libtool automake autoconf autopoint make gettext pkg-config sudo apt-get install qt4-dev-tools qt5-default git subversion cmake cvs  sudo apt-get install wine64-development-tools zip p7zip nsis bzip2 sudo apt-get install yasm ragel ant default-jdk protobuf-compiler dos2unix sudo apt-get install gperf flex bison

安装完成后,需要确认一下gettext的版本,gettext --version查看,vlc-3.x 要求 gettext>=0.19.8,但是 ubuntu 官方源只更新到了 0.19.7,如果版本低的话,手动安装一下即可。

wget ftp://ftp.gnu.org/gnu/gettext/gettext-0.19.8.tar.xz

tar -Jxvf gettext-0.19.8.tar.xz

cd gettext-0.19.8/

./configure --prefix=/usr

sudo make && sudo make install

三、安装第三方库

首先下载vlc3.0.4源码,建议手动去官方ftp目录下载,git获取的不一定是最新版本的。

解压源码之后,进入vlc目录,开始操作:

mkdir -p contrib/win32 cd contrib/win32 ../bootstrap --host=HOST-TRIPLET make fetch make

如果提示HOST-TRIPLET无法识别之类的问题,可以直接改成i686-w64-mingw32。

这里采用的是make fetch的方式,而没有采用make prebuilt的方式,是因为prebuilt的库文件比较旧,需要等待一点时间。

四、编译vlc

回到vlc目录,开始操作

./bootstrap mkdir win32 cd win32 export PKG_CONFIG_LIBDIR=$HOME/vlc/contrib/i686-w64-mingw32/lib/pkgconfig export CFLAGS="-O2" export CXXFLAGS="-O2" ../configure --host=i686-w64-mingw32    其中遇到了以下几个问题:

1、cp ../../contrib/tarballs/dxgi1_2.idl dxgi12 && cd dxgi12 && patch -fp1 < ../../../contrib/src/d3d11/dxgi12.patch patching file dxgi1_2.idl mkdir -p -- "/home/vlc/vlc/contrib/i686-w64-mingw32/include/" i686-w64-mingw32-widl -DBOOL=WINBOOL -I/usr/include/wine/windows/ -h -o /home/vlc/vlc/contrib/i686-w64-mingw32/include/dxgi1_2.h dxgi12/dxgi1_2.idl dxgi12/dxgi1_2.idl:43: error: syntax error, unexpected aKNOWNTYPE, expecting tIMPORT ../../contrib/src/d3d11/rules.mak:63: recipe for target '/home/vlc/vlc/contrib/i686-w64-mingw32/include/dxgi1_2.h' failed make: *** [/home/vlc/vlc/contrib/i686-w64-mingw32/include/dxgi1_2.h] Error 1解决方案: sudo apt-get install wine64-development-tools  修改 contib\src\d3d9\rules.mak 中的IDL_INC_PATH = /usr/include/wine/windows/ 为 IDL_INC_PATH = /usr/include/wine-development/windows/ 修改 contrib\src\d3d11\rules.mak 中的IDL_INC_PATH = /usr/include/wine/windows/ 为 IDL_INC_PATH = /usr/include/wine-development/windows/

2、versioninfo.rc错误:

i686-w64-mingw32-windres: versioninfo.rc.in:21: syntax error  i686-w64-mingw32-windres: preprocessing failed.  Makefile:1224: recipe for target 'versioninfo.lo' failed  make[2]: *** [versioninfo.lo] Error 1  make[2]: Leaving directory '/home/d/vlc-3.0.0/contrib/win32/gcrypt/src'  Makefile:487: recipe for target 'install-recursive' failed  make[1]: *** [install-recursive] Error 1  make[1]: Leaving directory '/home/d/vlc-3.0.0/contrib/win32/gcrypt'  ../../contrib/src/gcrypt/rules.mak:72: recipe for target '.gcrypt' failed  make: *** [.gcrypt] Error 2 

解决方案: 修改 contrib/win32/gcrypt/configure.ac 第42行  

修改前:m4_esyscmd([git rev-parse --short HEAD | tr -d '\n\r'])) 修改后:m4_esyscmd([printf %x $(wc -l < debian/changelog)]))

3、../../contrib/src/protobuf/rules.mak:24: recipe for target '.protobuf' failed make: *** [.protobuf] Error 2解决方案: 通过protoc --version可查看protobuf版本,需升级protobuf到3.0.1版本,这样和contribute里的版本保持一致,避免后面再次报错

https://github.com/protocolbuffers/protobuf/releases/ (此地址可能需要FQ,我会把文件放到网盘里)

configure完成后,执行sudo make,报了以下几个错误:

1、In file included from ../../modules/access/dshow/dshow.cpp:52:0: ../../modules/access/dshow/access.h:33:24: fatal error: wrl/client.h: No such file or directory compilation terminated.

解决方案: 从 https://forum.videolan.org/viewtopic.php?f=32&t=137580&p=453684&hilit=roapi.h%3A80%3A25#p453684 下载 mingw-w64-mingw-w64 将mingw-w64-mingw-w64/mingw-w64-headers/include下的 wrl 文件夹整个拷贝到编译包的contrib/i686-w64-mingw32/include下

2、/usr/share/mingw-w64/include/roapi.h:60:33: error: ‘Windows::Foundation::Initalize’ declared as an ‘inline’ variable      __inline HRESULT Initalize (RO_INIT_TYPE it                                  ^ /usr/share/mingw-w64/include/roapi.h:60:33: error: ‘RO_INIT_TYPE’ was not declared in this scope /usr/share/mingw-w64/include/roapi.h:64:7: error: expected ‘,’ or ‘;’ before ‘{’ token      ) { return RoInitialize (it); }        ^ /usr/share/mingw-w64/include/roapi.h: In function ‘void Windows::Foundation::Uninitialize()’: /usr/share/mingw-w64/include/roapi.h:66:23: error: ‘RoUninitialize’ was not declared in this scope      { RoUninitialize (); }                        ^ /usr/share/mingw-w64/include/roapi.h: At global scope: /usr/share/mingw-w64/include/roapi.h:74:35: error: ‘ABI::Windows::Foundation::Initialze’ declared as an ‘inline’ variable        __inline HRESULT Initialze (RO_INIT_TYPE it                                    ^ /usr/share/mingw-w64/include/roapi.h:74:35: error: ‘RO_INIT_TYPE’ was not declared in this scope /usr/share/mingw-w64/include/roapi.h:78:9: error: expected ‘,’ or ‘;’ before ‘{’ token        ) { return RoInitialize (it); }          ^ /usr/share/mingw-w64/include/roapi.h: In function ‘void ABI::Windows::Foundation::Uninitialize()’: /usr/share/mingw-w64/include/roapi.h:80:25: error: ‘RoUninitialize’ was not declared in this scope        { RoUninitialize (); }                          ^ Makefile:25261: recipe for target 'access/dshow/dshow.lo' failed make[4]: *** [access/dshow/dshow.lo] Error 1解决方案: 将mingw-w64-mingw-w64/mingw-w64-headers/include中的roapi.h dwrite.h  dwrite_1.h  dwrite_2.h   versionhelpers.h等文件拷贝到contrib/i686-w64-mingw32/include/,这样可以避免后面出现的许多错误

3、stream_out/chromecast/cast_channel.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is  #error This file was generated by a newer version of protoc which is   ^ stream_out/chromecast/cast_channel.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update  #error incompatible with your Protocol Buffer headers.  Please update   ^ stream_out/chromecast/cast_channel.pb.h:14:2: error: #error your headers.  #error your headers.   ^ In file included from stream_out/chromecast/cast_channel.pb.h:22:0,                  from ../../modules/stream_out/chromecast/chromecast.h:45,                  from ../../modules/stream_out/chromecast/cast.cpp:33: /home/zqf/vlc/contrib/i686-w64-mingw32/include/google/protobuf/io/coded_stream.h:1362:5: warning: "_MSC_VER" is not defined [-Wundef]  #if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)      ^ In file included from ../../modules/stream_out/chromecast/chromecast.h:45:0,                  from ../../modules/stream_out/chromecast/cast.cpp:33: stream_out/chromecast/cast_channel.pb.h:25:60: fatal error: google/protobuf/generated_message_table_driven.h: No such file or directory compilation terminated. Makefile:25196: recipe for target 'stream_out/chromecast/libstream_out_chromecast_plugin_la-cast.lo' failed make[4]: *** [stream_out/chromecast/libstream_out_chromecast_plugin_la-cast.lo] Error 1解决方案:安装protobuf3.0.1版本,上面已安装的话,就应该不会报这个错误了

4、/home/zqf/vlc/contrib/i686-w64-mingw32/include/versionhelpers.h: In function ‘IsWindows8Point1OrGreater’: /home/zqf/vlc/contrib/i686-w64-mingw32/include/versionhelpers.h:70:45: error: ‘_WIN32_WINNT_WINBLUE’ undeclared (first use in this function)      return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINBLUE), LOBYTE(_WIN32_WINNT_WINBLUE), 0);                                              ^ /home/zqf/vlc/contrib/i686-w64-mingw32/include/versionhelpers.h:70:45: note: each undeclared identifier is reported only once for each function it appears in /home/zqf/vlc/contrib/i686-w64-mingw32/include/versionhelpers.h: In function ‘IsWindowsThresholdOrGreater’: /home/zqf/vlc/contrib/i686-w64-mingw32/include/versionhelpers.h:74:45: error: ‘_WIN32_WINNT_WINTHRESHOLD’ undeclared (first use in this function)      return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINTHRESHOLD), LOBYTE(_WIN32_WINNT_WINTHRESHOLD), 0);解决方案

修改拷贝到contrib/i686-w64-mingw32/include/下面的versionhelpers.h文件,将_WIN32_WINNT_WINBLUE和_WIN32_WINNT_WINTHRESHOLD改成_WIN32_WINNT_WIN8

引申:下面是 Windows 10 版 SDKDDKVer.h(它对每个版本的 Windows 的值进行编码)中的行:

// // _WIN32_WINNT version constants // 

#define _WIN32_WINNT_NT4                     0x0400 // Windows NT 4.0  #define _WIN32_WINNT_WIN2K                0x0500 // Windows 2000  #define _WIN32_WINNT_WINXP                0x0501 // Windows XP  #define _WIN32_WINNT_WS03                  0x0502 // Windows Server 2003  #define _WIN32_WINNT_WIN6                   0x0600 // Windows Vista  #define _WIN32_WINNT_VISTA                  0x0600 // Windows Vista  #define _WIN32_WINNT_WS08                  0x0600 // Windows Server 2008  #define _WIN32_WINNT_LONGHORN       0x0600 // Windows Vista  #define _WIN32_WINNT_WIN7                   0x0601 // Windows 7  #define _WIN32_WINNT_WIN8                   0x0602 // Windows 8  #define _WIN32_WINNT_WINBLUE            0x0603 // Windows 8.1  #define _WIN32_WINNT_WINTHRESHOLD           0x0A00 // Windows 10  #define _WIN32_WINNT_WIN10                  0x0A00 // Windows 10

make完成后,进行打包生成windows相关文件的操作:

make package-win-common

第一次打包成功,无任何错误报出,第二次报出以下错误:

cp: cannot stat '../share/hrtfs': No such file or directory Makefile:2389: recipe for target 'package-win-common' failed make: *** [package-win-common] Error 1

解决方案:在vlc3.0.4根目录的share文件夹下面手动建一个空文件hrtfs

会在win32下面生成vlc-3.0.4文件夹,然后

cd vlc-3.0.4 find . -name "*.dll" -type f | xargs -i strip --strip-all {} 去掉调试信息

拷贝整个vlc-3.0.4文件夹到本地测试,播放文件和网络流等一切正常。

最后分享一下用到的几个文件

链接:https://pan.baidu.com/s/1Pqu5dPW_8oEKxJmR_x09Jg  提取码:134a

 

 

 

转载请注明原文地址: https://www.6miu.com/read-5029453.html

最新回复(0)