为了使用最新的VLC库,需要自己对VLC-QT库进行编译,编译用到了CMake。下面是我的编译过程:
作者给出了一份编译说明文档
Building VLC-Qt
Requirements
VLC-Qt can be built with any common compiler (g++, clang, MSVC, MinGW).
Build files are generated using CMake (3.0.2 or later).All stable versions of VLC since 2.1 work with VLC-Qt.
Qt 5 (version 5.5 or later recommende) is recommended as Qt 4 support is
considered deprecated. Binaries will always be provided for latest Qt version
released at the time of release.Make sure you have git submodules initialised or you may experience build issues.
CMake configuration
There are some specific CMake flags may need:
COVERAGE: generate coverage report, OFF by defaultDEBUG_SUFFIX: add debug suffix ‘d’ to the libraries, ON on Widows, OFF elsewhereLIBVLC_VERSION: set VLC version you are compiling with to disable unsupportedfeatures, should be defined as base 16 integer like `0x020200`, defaults to latest stable VLC versionSTATIC: build statically, OFF by defaultSYSTEM_QML: detect and install to system QML location, OFF by defaultExtra platform specific flags:
WITH_GLES: link OpenGL ES v2 on Windows, OFF by default, only needed for
Qt 5.4 and lower (deprecated)WITH_HOMEBREW: let system know you are using Homebrew provided Qt,
OFF by default, macOS onlyWITH_X11: link with X11, required by some Linux distributions, OFF by defaultBuilding in separate
builddirectory is recommended.
There is atesttarget to run automatic tests for the library.Platform specific instructions
macOS
You need to prepare VLC libraries and plugins before building. After
cmakerunmake prepare, then re-runcmake. Build as a normal library or application.Supported generators are
makeandninja.
Qt inPATHand VLC in/Applicationswill be used.Make example:
1
2
3
4
5
6
7
8
9 > $ export PATH=$PATH:/path/to/Qt/5.6/clang_64/bin
> $ mkdir build
> $ cd build
> $ cmake .. -DCMAKE_BUILD_TYPE=Debug
> $ make prepare
> $ cmake ..
> $ make -j8
> $ make install
>
>
Windows
Build as a normal library or application.
Make sure you always use debug libraries with debug build and release libraries
with release build after using it in your project.Supported generators for MSVC are
nmake,jomandninja;
for MinGW:mingw32-makeandninja.
Run specific Qt shell to select its version. VLC path needs to be specified manually.Ninja example for MSVC64:
1
2
3
4
5
6
7
8
9
10 > $ md build
> $ cd build
> $ cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug ^
> -DCMAKE_INSTALL_PREFIX="E:/install/vlc-qt/msvc64" ^
> -DLIBVLC_LIBRARY="E:/vlc/win64/sdk/lib/libvlc.lib" ^
> -DLIBVLCCORE_LIBRARY="E:/vlc/win64/sdk/lib/libvlccore.lib" ^
> -DLIBVLC_INCLUDE_DIR="E:/vlc/win64/sdk/include"
> $ ninja
> $ ninja install
>
>
Linux
Install requirements from your distribution’s repository.
Supported generators aremakeandninja.Make example:
1
2
3
4
5
6 > $ mkdir build
> $ cd build
> $ cmake .. -DCMAKE_BUILD_TYPE=Debug
> $ make -j8
> $ make install
>
按照说明,我在win10下结合VS2015进行编译
1. 注意:不要用powershell,要用cmd
在源码目录新建一个文件夹(比如 build),在这个文件夹内打开cmd,输入命令
1 | cmake ../ -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="F:/VLC-QT/bin" -DLIBVLC_LIBRARY="F:/vlc/sdk/lib/libvlc.lib" -DLIBVLCCORE_LIBRARY="F:/vlc/sdk/lib/libvlccore.lib" -DLIBVLC_INCLUDE_DIR="F:/vlc/sdk/include" |
这里用到了Ninja构建系统,下载后放到cmake目录就好了,就是一个单exe文件。这一大串命令可以精简一下,把包含目录和库文件作为变量写进CMakeList.txt文件
1 | # 根目录下的CMakeList.txt |
然后执行命令
1 | cmake ../ -GNinja |
就简单多了
其中用到了libvlc的库,需要提前下载,下载地址VLC FTP archive
如果这一步提示错误,找不到编译器 No CMAKE_C_COMPILER could be found. No CMAKE_CXX_COMPILER could be found. ,需要先临时设置一下VS Compiler的环境变量。
cd 到 VS VCC的目录,比如C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC ,在这个目录下有一个脚本vcvarsall.bat,稍微看一下这个脚本就知道这是设置vc用到的所有环境变量的。执行:
1 | vcvarsall.bat x86 #这里将会把文件编译成32位的程序,需要64位的,把参数变成x64或者amd64 |
然后再次执行上面的cmake命令,这是就会显示
1 | -- The C compiler identification is MSVC 19.0.24215.1 |
表示VS2015的编译器已经找到了。
但是又有了新的错误,找不到Qt5CoreConfig.cmake等,因为用到了QT,所以也要把qt库添加进来。
首先找到你的Qt5CoreConfig.cmake所在路径,然后在根目录的CMakeList.txt文件中添加一个变量Qt5Core_DIR,其他类似的错误也是一样的方式添加。
1 | SET(Qt5Core_DIR D:/Qt/Qt5.9.1/5.9.1/msvc2015/lib/cmake/Qt5Core) |
再次cmake就会通过了。
然后执行
1 | ninja |
就开始编译啦。编译完成后,会在build/src目录下看到生成的dll和lib文件。至此VLC-QT库就自己编译好了,可以拿去用啦。
CMake GUI 方式
上面是用命令行的方式编译成Ninja工程,这里演示一下用GUI的方式编译为VS2015工程的过程。
GUI方式可以方便的添加环境变量,不用去编辑CMakeList.txt文件。在configure过程中出现的错误一一排除就可以啦。
操作过程视频:
编译效果
把编译好的dll放到程序里看看效果吧