下面介绍一下如何在Linux系统下构建TigerVNC项目:
TigerVNC 在构建的时候需要很多依赖库, 依赖库列表如下:
ffmpeg、hogweed、libjpeg-turbo、PAM、gmp、pixman、FLTK、Xft、p11-kit、freetype-config
如果使用的操作系统的源中包含对应的依赖库,我们可以通过apt/yum包管理器安装对应的库,命令如下所示:
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev ffmpeg \
libhogweed4 libhogweed-dev libjpeg-turbo8-dev libpam-dev libgmp3-dev libpam-dev \
libpixman-1-dev libfltk1.3-dev libfreetype6-dev libxft-dev libtasn1-6-dev libunbound-dev \
libp11-kit-dev libzstd-dev libbrotli-dev libpng-dev libxcursor-dev libbz2-dev
由于通过apt安装的库通常为动态库, 如果想降低发布程序依赖文件的数量实现静态发布, 我们需要依赖库的静态库。
镜像源安装的库中没有静态库的话, 对应的静态库需要从源码来进行编译安装, 下面介绍一下各个库的静态库编译方法:
# 安装FLTK1.3.3
# 下载地址: https://www.fltk.org/
# FLTK是一种使用C++开发的GUI工具包,它可以应用于Unix,Linux,MS-Windows95/98/NT/2000和MacOS操作系统平台。
wget https://www.fltk.org/pub/fltk/1.3.8/fltk-1.3.8-source.tar.gz
tar -zxvpf fltk-1.3.8-source.tar.gz
cd fltk-1.3.8
./configure --prefix=/usr/local/fltk --enable-static --enable-shared
make
make install
# 安装YASM 1.3.0
# 下载地址:http://www.tortall.net/projects/yasm/releases/
cd yasm-1.3.0/
./configure --enable-static --enable-shared
make
make install
# 安装FFmpeg
# 下载地址: http://ffmpeg.org/download.html#releases
./configure --enable-static --enable-shared
make
make install
./ffmpeg -version
# 安装GETEXT
# 下载地址: https://www.gnu.org/software/gettext/
# Kylin安装完成之后 需要将对应的文件拷贝到相应的目录下
# libpath /usr/lib/x86_64-linux-gnu/ include_dir=/usr/include/ bindir=/usr/bin
./configure --prefix=/usr/local/gettext --enable-static --enable-shared
make
make install
# 安装GMP
# 下载地址:https://gmplib.org/
# Kylin安装完成之后 需要将对应的文件拷贝到相应的目录下
# /usr/lib/x86_64-linux-gnu/libgmp.so
# /usr/include/x86_64-linux-gnu/gmp.h
tar -xf gmp-6.2.1.tar.xz
./configure --enable-static --enable-shared
make
make install
# 安装Libnettle 3.5
# 下载地址:https://ftp.gnu.org/gnu/nettle/
# Kylin 文件拷贝目录 /usr/lib/x86_64-linux-gnu/ /usr/include/nettle/ 需要拷贝pkgconfig里面的内容
./configure --prefix=/usr/local/libnettle --enable-static --enable-shared
make -j4
make install
# 安装Libtasn1 4.9
# 下载地址:https://ftp.gnu.org/gnu/libtasn1/
# Kylin 文件拷贝目录/usr/lib/x86_64-linux-gnu/ /usr/include/ 需要拷贝pkgconfig里面的内容
./configure --prefix=/usr/local/libtasn1 --enable-static --enable-shared
make
make install
# 安装Libunistring
# 下载地址:https://www.gnu.org/software/libunistring/#TOCdownloading
# Kylin 文件拷贝目录/usr/lib/x86_64-linux-gnu/ /usr/include/ 需要拷贝pkgconfig里面的内容
./configure --prefix=/usr/local/libunistring --enable-static --enable-shared
make
make install
# 安装libunbound
# 下载地址:https://nlnetlabs.nl/projects/unbound/download/
./configure --enable-static --enable-shared
make
sudo make install
# 安装pll-kit
# 下载地址:https://github.com/p11-glue/p11-kit/releases
./configure --enable-static --enable-shared
make
sudo make install
# 安装GnuTLS
# 下载地址:https://www.gnutls.org/
tar -xf gnutls-3.6.11sudo.tar.xz
./configure --prefix=/usr/local/gnutls --with-nettle-mini=/usr/local/libnettle/lib --enable-static --enable-shared
make
make install
# 安装 jpeg-turbo
# 下载地址:https://github.com/libjpeg-turbo/libjpeg-turbo
# Kylin文件拷贝路径:/usr/lib/x86_64-linux-gnu/ /usr/include/
# /opt/libjpeg-turbo/include/jpeglib.h
# 添加对应的环境变量
# vim ~/.bashrc
# export JPEG_LIBRARY="/opt/libjpeg-turbo/lib64/libjpeg.so"
# export JPEG_INCLUDE_DIR="/opt/libjpeg-turbo/include"
# export PKG_CONFIG_PATH=/opt/libjpeg-turbo/lib64/pkgconfig:${PKG_CONFIG_PATH}
cd libjpeg-turbo
mkdir build
cd build
cmake -G"Unix Makefiles" ..
sudo make
sudo make install
# 安装PAM库
# 下载地址: https://github.com/linux-pam/linux-pam/releases
# Kylin文件拷贝路径/usr/lib/x86_64-linux-gnu/ /usr/include/security/ /etc/目录 /sbin/目录
tar -xf Linux-PAM-1.4.0.tar.xz
./configure --prefix=/usr/local/pam --enable-static --enable-shared
make
make install
将TigerVNC\cmake\StaticBuild.cmake文件中的第68行修改成如下:
set(GNUTLS_LIBRARIES "-Wl,-Bstatic -lpthread -lgnutls -lzstd -lunistring -liconv -lbrotlienc -lbrotlicommon -lbrotlidec")
# 静态构建tigerVNC
tar -xvf tigervnc-1.13.1.tar.gz
cd tigervnc-1.13.1/
mkdir build
cd build/
cmake -DENABLE_GNUTLS=OFF -DBUILD_STATIC=1 ..
make -j8
sudo make install
1.编译VNCViewer 过程中报错:
/usr/bin/ld: /usr/local/fltk/lib/libfltk.a(Fl_Window_shape.o): undefined reference to symbol 'dlsym@@GLIBC_2.2.5'
解决办法:
是因为缺少dl库和png库
# VNCViewr 编译报错修改它的CMakelist.txt文件
# https://www.cnblogs.com/w4ngzhen/p/16807265.html
# 添加对应的库 dl 和 png
# 修改第64行
if(X11_Xrandr_LIB)
add_definitions(-DHAVE_XRANDR)
target_link_libraries(vncviewer X11 dl png ${X11_Xrandr_LIB})
endif()
2.编译报错如下:
undefined reference to symbol ‘png_get_image_height@@PNG12_0
解决办法:
# 缺少对libpng库的链接, 你正在使用的程序或库依赖于libpng 库,在对应的CMakeList.txt中添加对应的png库依赖。
# -lpng
3.编译报错:
/usr/bin/msgfmt: cannot locate ITS rules for evince-pdfdocument.metainfo.xml.in
解决办法:
# 是因为缺少appstream库
# appstream 下载地址: https://www.freedesktop.org/wiki/Distributions/AppStream/
# 需要安装 appstream
mkdir build
cd build
cmake ..
make
4.编译报错:
Package gmp was not found in the pkg-config search path. Perhaps you should add the directory containing `gmp.pc'
to the PKG_CONFIG_PATH environment variable Package 'gmp', required by 'world', not found
解决办法:
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:${PKG_CONFIG_PATH}
tigerVNC生成的各个应用说明:
vncviewer # 是跨平台的TigerVNC客户端 使用FLTK编写
Xvnc # 是Unix系统下的TigerVNC的服务端和X11转发器
vncpasswd # 用来修改VNC的密码
vncconfig # 用来配置和控制正在运行的VNC
x0vncserver # vnc服务端,可以用来转发X11指令
[email protected] # 用于启动与Xvnc和其中一个的用户会话的服务系统上可用的桌面环境
# TigerVNC服务器的密码保存在~/.vnc/passwd文件中。如果该文件不存在,则会自动创建它
Linux下TigerVNC服务端的启动方法:
# 服务端免密启动
./x0vncserver SecurityTypes=None display=':0' MaxDisconnectionTime=2000
# 加密启动服务端
./x0vncserver PasswordFile="/home/feifei/.vnc/passwd" display=':0' MaxDisconnectionTime=2000 rfbport=5999
有时候如果CMake版本太低的话, 通过CMake编译TigerVNC项目的时候会报错, 这时候可以通过下面的命令升级CMake。
# 查看cmake的信息
sudo apt info cmake
# 删除旧版本CMake
sudo apt remove -y
# 下载新版本的CMake
wget https://cmake.org/files/v3.12/cmake-3.12.4.tar.gz
# 解压构建
tar -zxvf cmake-3.12.4.tar.gz
cd cmake-3.12.4
sudo ./bootstrap --prefix=/usr/local
sudo make
sudo make install