在CentOS7上编译VLC4

在CentOS7上编译VLC4

Authror: kagula
Date: 2019-2-12

环境
[1]GCC 6.5
[2]QT 5.9.2
[3]VLC 4.0.0-dev
[4]FFMPEG 3.4.5
[5]CentOS7.4-64bits

正文

Step1: 如果是在Windows上Git下来, 复制到CentOS上, 需要做些额外的工作
./bootstrap
提示
-bash: ./bootstrap: /bin/sh^M: bad interpreter: No such file or directory

解决
dos2unix bootstrap

再次运行bootstrap
提示
' is already registered with AC_CONFIG_FILES.
解决
dos2unix configure.ac

然后又出现莫明奇妙问题, 采用类似上面的办法执行
 dos2unix aclocal.m4
 
运行bootstrap终于成功。 

Step2:  准备FFMpeg第三方库
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -xvf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure && make && make install

wget https://www.ffmpeg.org/releases/ffmpeg-3.4.5.tar.gz
tar -xvf ffmpeg-3.4.5.tar.gz
cd ffmpeg-3.4.5
./configure  --enable-shared
这里可以跟上--disable-yasm参数,如果编译FFMPEG过程中没有为GCC加上-fPIC参数。
make
make install

Step3:  准备liba52第三方库
wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
tar -zxvf a52dec-0.7.4.tar.gz
./configure --enable-shared --disable-static
make 
显示错误信息如下
make[1]: Entering directory `/root/download/a52dec-0.7.4/liba52'
/bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I../include -I../include -I../include    -g  -O3 -fomit-frame-pointer  -prefer-non-pic -c parse.c
gcc -DHAVE_CONFIG_H -I. -I. -I../include -I../include -I../include -g -O3 -fomit-frame-pointer -c parse.c -o parse.lo
parse.c:306:23: warning: always_inline function might not be inlinable [-Wattributes]
 static inline int16_t dither_gen (a52_state_t * state)
                       ^~~~~~~~~~
parse.c:292:19: warning: always_inline function might not be inlinable [-Wattributes]
 static inline int zero_snr_offsets (int nfchans, a52_state_t * state)
                   ^~~~~~~~~~~~~~~~
In file included from parse.c:32:0:
bitstream.h:66:23: warning: always_inline function might not be inlinable [-Wattributes]
 static inline int32_t bitstream_get_2 (a52_state_t * state, uint32_t num_bits)
                       ^~~~~~~~~~~~~~~
bitstream.h:53:24: warning: always_inline function might not be inlinable [-Wattributes]
 static inline uint32_t bitstream_get (a52_state_t * state, uint32_t num_bits)
                        ^~~~~~~~~~~~~
/bin/sh ../libtool --mode=link gcc  -g  -O3 -fomit-frame-pointer  -prefer-non-pic  -o liba52.la -rpath /usr/local/lib -no-undefined bitstream.lo imdct.lo bit_allocate.lo parse.lo downmix.lo -lm
rm -fr .libs/liba52.la .libs/liba52.* .libs/liba52.*
gcc -shared  bitstream.lo imdct.lo bit_allocate.lo parse.lo downmix.lo  -lm  -Wl,-soname -Wl,liba52.so.0 -o .libs/liba52.so.0.0.0
/usr/bin/ld: imdct.lo: relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: bit_allocate.lo: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: parse.lo: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: downmix.lo: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

使用下面的命令把四个lo文件的-fPIC参数加上重新make,具体命令如下
cd liba52
gcc -DHAVE_CONFIG_H -I. -I. -I../include -I../include -I../include -g -O3 -fomit-frame-pointer -fPIC -c bit_allocate.c -o bit_allocate.lo
gcc -DHAVE_CONFIG_H -I. -I. -I../include -I../include -I../include -g -O3 -fomit-frame-pointer -fPIC -c parse.c -o parse.lo
gcc -DHAVE_CONFIG_H -I. -I. -I../include -I../include -I../include -g -O3 -fomit-frame-pointer -fPIC -c downmix.c -o downmix.lo
gcc -DHAVE_CONFIG_H -I. -I. -I../include -I../include -I../include -g -O3 -fomit-frame-pointer -fPIC -c imdct.c -o imdct.lo
然后返回上级目录make成功。
make install

Step4: Alsa
ALSA全称是Advanced Linux Sound Architecture
yum install -y *alsa*

Step5: 安装Qt
参考
Linux CentOS7 安装 Qt 5.9.2
https://www.cnblogs.com/lsgxeva/p/7688884.html
注意很多没勾的item一定要勾上。

Final Step: 编译VLC
./configure --enable-debug  --enable-run-as-root  --with-qt-dir=/opt/Qt5.9.2/5.9.2/gcc_64 --with-qt-includes=/opt/Qt5.9.2/5.9.2/gcc_64/include  --with-qt-libraries=/opt/Qt5.9.2/5.9.2/gcc_64/lib


export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH

export QT_CFLAGS="-I/opt/Qt5.9.2/5.9.2/gcc_64/include/ \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtWidgets \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtDBus \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtGui \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtOpenGL \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtSvg \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtUiTools \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/Qt3Support \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtCore \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtDesigner \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtNetwork \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtSql \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtTest \
-I/opt/Qt5.9.2/5.9.2/gcc_64/include/QtXml"
export QT_LIBS="-lQt5Core -lQt5Gui -lQt5Svg -lQt5Xml -lQt5Widgets -lX11"

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.9.2/5.9.2/gcc_64/lib:/usr/lib64/

查看下环境变量,是否正确设置,其中/usr/lib64是X11的搜索路径
echo $LD_LIBRARY_PATH


修改QT_CFLAGS和QT_LIBS环境变量后需要重新运行./configure --enable-debug
保险点的话,configure前先把Makefile文件删除。

make
make install
然后在图形环境下运行vlc目录下的vlc(make成功后就会生成)
你可以看到VLC media player图形界面已经正常启来,播放本地mp4文件OK


常见问题
Q1:编译VLC
提示下面的错误
configure: error: Missing libav or FFmpeg. Pass --disable-avcodec to ignore this error.

A1:
参考资料
https://stackoverflow.com/questions/41692115/vlc-3-0-configure-gives-missing-libav-or-ffmpeg-despite-i-have-them
 
echo $PKG_CONFIG_PATH
发现这里变量里面啥都没有

Then I searched at /usr directory for libavcodec.pc , and found it:

find /usr -name "libav*.pc"

/usr/local/lib/pkgconfig/libavdevice.pc
/usr/local/lib/pkgconfig/libavfilter.pc
/usr/local/lib/pkgconfig/libavformat.pc
/usr/local/lib/pkgconfig/libavcodec.pc
/usr/local/lib/pkgconfig/libavutil.pc

临时修改路径
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH

Q2:
执行make
出现下面的错误信息
make[4]: Entering directory `/root/download/vlc/po'
.po does not exist. If you are a translator, you can create it through 'msginit'.
.po-create] Error 1
make[4]: Leaving directory `/root/download/vlc/po'
.po] Error 2 [ach
make[3]: Leaving directory `/root/download/vlc/po'
make[2]: *** [stamp-po] Error 2
make[2]: Leaving directory `/root/download/vlc/po'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/download/vlc'
make: *** [all] Error 2

A:
这是由于从windows上git pull下来,再复制到CentOS上引起的问题
在CentOS上重新git pull,  如有冲突覆盖本地文件即可.

Q3:
/bin/sh: moc: command not found

A
moc command在下面的路径中
/opt/Qt5.9.2/5.9.2/gcc_64/bin
echo $PATH
这个路径没在search path中, 需要加进去。
vi /etc/profile
export PATH=$PATH:/opt/Qt5.9.2/5.9.2/gcc_64/bin

使修改生效
source /etc/profile


Q4
make[2]: Entering directory `/root/download/vlc/modules'
  CXX      gui/qt/libqt_plugin_la-qt.lo
gui/qt/qt.cpp:42:24: fatal error: QApplication: No such file or directory

A
修改modules/gui/qt/qt.cpp,使用绝对路径!以为最多改十来个文件就可以了,结果改了数不清的文件,
下次遇到类似“/opt/Qt5.9.2/5.9.2/gcc_64/include/QtWidgets”这个路径下的文件无法被search到的问题,还是重新configure吧, 
以为可以偷懒,结果手动改了五,六个小时
得不尝失!

注意,这里修改Makefile文件添加include search path重新make的办法是没用的,只能重新使用configure命令使用新添加的include path生效.

Q5
不能播放Darwin的RTSP源的问题

A
未知, 也许是dev分支的缘故,待补充。


备注
[1]
-fPIC 作用于编译阶段,告诉编译器产生与位置无关代码(Position-Independent Code),
则产生的代码中,没有绝对地址,全部使用相对地址,故而代码可以被加载器加载到内存的任意
位置,都可以正确的执行。这正是共享库所要求的,共享库被加载时,在内存的位置不是固定的。
具体参考<<gcc 编译参数 -fPIC 的详解和一些问题>>
https://blog.csdn.net/a_ran/article/details/41943749 

猜你喜欢

转载自blog.csdn.net/lee353086/article/details/87169028