Skip to content

Latest commit

 

History

History
528 lines (403 loc) · 20.5 KB

Linux_zh_CN.md

File metadata and controls

528 lines (403 loc) · 20.5 KB

为 Linux 编译

作者:康林 [email protected]

环境

操作系统

  • Ubuntu

    ~$ lsb_release -a
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 22.04.3 LTS
    Release:	22.04
    Codename:	jammy
    
  • Debian

    ~$ lsb_release -a
    No LSB modules are available.
    Distributor ID:	Debian
    Description:	Debian GNU/Linux 12 (bookworm)
    Release:	12
    Codename:	bookworm
    

Qt Creator

版本:v12.0.2。建议使用 v5.0.2 及以后版本,以前版本对 CMake 支持不够。

工具

  • 安装开发工具软件包

    ~$ sudo apt install build-essential
    
    • 开发工具软件包已经包括安装以下内容:
      • 编译器

        • GCC/G++

          ~$ sudo apt install g++ gcc
          
      • automake、autoconf、make、fakeroot

        ~$ sudo apt install automake autoconf make fakeroot
        
  • GIT: http://www.git-scm.com

    ~$ sudo apt install git
    
  • CMAKE: http://www.cmake.org

    版本: 3.27.0

    ~$ sudo apt install cmake
    
  • 打包工具: debhelper

    ~$ sudo apt install debhelper
    
  • Qt

    • Qt 官方发行版本: https://download.qt.io/official_releases/qt/

    • Qt5: 当前版本: Qt 5.12.12

      • 系统自带:

        ~$ sudo apt install qttools5-dev qttools5-dev-tools qtbase5-dev qtbase5-dev-tools qtmultimedia5-dev qtlocation5-dev libqt5svg5-dev libqtermwidget5-0-dev
        
    • Qt6: 当前版本:6.4.2

      • 系统自带:

        ~$ sudo apt install qt6-tools-dev qt6-tools-dev-tools qt6-base-dev qt6-base-dev-tools qt6-qpa-plugins libqt6svg6-dev qt6-l10n-tools qt6-translations-l10n qt6-scxml-dev qt6-multimedia-dev libqt6serialport6-dev
        
  • [可选] IDE: Qt Creator。建议使用 v5.0.2 及以后版本,以前版本对 CMake 支持不够。

    ~$ sudo apt install qtcreator
    
  • OpenGL: 运行 Qt 需要

    ~$ sudo apt install libglu1-mesa-dev
    
  • Doxygen: http://www.doxygen.nl/

    ~$ sudo apt install doxygen
    

依赖库

玉兔公共库

此库默认放在与本项目同级目录下,如果没有在同级目录下,则必须指定 CMake 参数: -DRabbitCommon_ROOT=[RabbitCommon 安装目录]

~$ git clone https://github.com/KangLin/RabbitCommon.git

FreeRDP

  • 使用系统预编译开发库

    ~$ sudo apt install freerdp2-dev
    
  • 使用 vcpkg

    • 源码位置: https://github.com/microsoft/vcpkg/

      ~$ git clone https://github.com/microsoft/vcpkg.git
      ~$ cd vcpkg
      ~/vcpkg$ ./bootstrap-vcpkg.sh
      ~/vcpkg$ vcpkg install freerdp
      
    • 指定 CMake 参数:-DCMAKE_TOOLCHAIN_FILE=[vcpkg 安装目录]/scripts/buildsystems/vcpkg.cmake

    • 使用 vcpk , FreeRDP 服务不是默认功能,所以需要你手动指定。

  • 从源码编译

    • 源码位置:https://github.com/FreeRDP/FreeRDP

    • 编译详见:https://github.com/FreeRDP/FreeRDP/wiki/Compilation

        ~$ git clone https://github.com/FreeRDP/FreeRDP.git
        ~$ cd FreeRDP
        ~/FreeRDP$ mkdir build
        ~/FreeRDP/build$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=`pwd`/install -DWITH_SERVER=ON
        ~/FreeRDP/build$ cmake --build . --config Release --target install
      
    • 指定 CMake 参数:

      • -DBUILD_FREERDP=ON
      • -DFreeRDP-Client_DIR=[freerdp 安装目录]/lib/cmake/FreeRDP-Client2
      • -DFreeRDP_DIR=[freerdp 安装目录]/lib/cmake/FreeRDP2
      • -DWinPR_DIR=[freerdp 安装目录]/lib/cmake/WinPR2

LibVNCServer

  • 使用系统预编译开发库

    ~$ sudo apt install libvncserver-dev
    
  • 从源码编译

RabbitVNC

  • 从源码编译 源码位置: https://github.com/KangLin/RabbitVNC

    ~$ sudo apt install libpixman-1-dev
    ~$ git clone https://github.com/KangLin/RabbitVNC.git
    ~$ cd RabbitVNC
    ~/RabbitVNC$ mkdir build
    ~/RabbitVNC$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=`pwd`/install
    ~/RabbitVNC$ cmake --build . --config Release --target install
    
  • 指定 CMake 参数:-DRabbitVNC_DIR=[RabbitVNC 安装目录]/lib/cmake/RabbitVNC

TigerVNC

  • 从源码编译

官方只是个应用程序,不支持库。详见:TigerVNC/tigervnc#1123
所以本人在官方基础上做了修改。源码位置:https://github.com/KangLin/tigervnc

~$ sudo apt install libpixman-1-dev
~$ git clone https://github.com/KangLin/tigervnc.git
~$ cd tigervnc
~/tigervnc$ mkdir build
~/tigervnc$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=`pwd`/install
~/tigervnc$ cmake --build . --config Release --target install
  • 指定 CMake 参数:-Dtigervnc_DIR=[TigerVNC 安装目录]/lib/cmake/tigervnc

libdatachannel

  • 使用 vcpkg
    • 源码位置: https://github.com/microsoft/vcpkg/

      ~$ git clone https://github.com/microsoft/vcpkg.git
      ~$ cd vcpkg
      ~/vcpkg$ vcpkg install libdatachannel
      
    • 指定 CMake 参数:-DCMAKE_TOOLCHAIN_FILE=[vcpkg 安装目录]/scripts/buildsystems/vcpkg.cmake

  • 从源码编译
    • 源码位置: https://github.com/paullouisageneau/libdatachannel

    • 编译详见: https://github.com/paullouisageneau/libdatachannel/blob/master/BUILDING.md

      ~$ git clone https://github.com/paullouisageneau/libdatachannel.git
      ~$ cd libdatachannel
      ~/libdatachannel$ git submodule update --init --recursive
      ~/libdatachannel$ mkdir build
      ~/libdatachannel$ cd build
      ~/libdatachannel/build$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=`pwd`/install
      ~/libdatachannel/build$ cmake --build . --config Release --target install
      
    • 指定 CMake 参数: -DLibDataChannel_DIR=[libdatachannel 安装目录]/lib/cmake/LibDataChannel

QXmpp

  • 从源码编译
    • 源码位置: https://github.com/qxmpp-project/qxmpp

      ~$ git clone https://github.com/qxmpp-project/qxmpp.git
      ~$ cd qxmpp
      ~/qxmpp$ mkdir build
      ~/qxmpp$ cd build
      ~/qxmpp/build$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=`pwd`/install -DQt5_DIR=[Qt5 安装目录]/lib/cmake/Qt5
      ~/qxmpp/build$ cmake --build . --config Release --target install
      
    • 指定 CMake 参数: -DQXmpp_DIR=[QXmpp 安装目录]/lib/cmake/qxmpp

QTermWidget

  • 使用系统预编译开发库

    ~$ sudo apt install libqtermwidget5-0-dev
    
  • 从源码编译

libssh

  • 使用系统预编译开发库

    ~$ sudo apt install libssh-dev 
    
  • 使用 vcpkg

    • 源码位置: https://github.com/microsoft/vcpkg/

      ~$ git clone https://github.com/microsoft/vcpkg.git
      ~$ cd vcpkg
      ~/vcpkg$ vcpkg install libssh
      
    • 指定 CMake 参数:-DCMAKE_TOOLCHAIN_FILE=[vcpkg 安装目录]/scripts/buildsystems/vcpkg.cmake

  • 从源码编译

    • 源码位置: https://www.libssh.org
    • 指定 CMake 参数:-Dlibssh_DIR=[libssh 安装目录]/lib/cmake/libssh

QtService

  • 从源码编译
    • 源码位置:: https://github.com/KangLin/qt-solutions/

      ~$ git clone https://github.com/KangLin/qt-solutions.git
      ~$ cd qt-solutions
      ~/qt-solutions$ mkdir build
      ~/qt-solutions$ cd build
      ~/qt-solutions/build$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=`pwd`/install
      ~/qt-solutions/build$ cmake --build . --config Release --target install
      
    • 指定 CMake 参数: -DQtService_DIR=[QtService 安装目录]/lib/cmake/QtService

编译本项目

  • 项目位置:https://github.com/KangLin/RabbitRemoteControl

  • 下载源码

    ~$ git clone https://github.com/KangLin/RabbitRemoteControl.git
    
  • CMake 参数

    • RabbitCommon_ROOT: RabbitCommon 源码位置
    • BUILD_CLIENT: 编译客户端。默认为 ON
    • BUILD_SERVICE: 编译服务器端。默认依赖是否有 QtService
    • BUILD_PLUGINS: 编译插件。默认为 ON
    • BUILD_APP: 编译应用程序。默认为 ON
    • BUILD_DOCS: 编译文档。默认为 OFF
    • BUILD_SHARED_LIBS: 编译动态库。默认为 ON
    • BUILD_FREERDP:是否编译 FreeRDP。 默认为 OFF
    • WinPR_DIR:PATH: [freerdp 安装目录]/lib/cmake/WinPR2
    • FreeRDP_DIR: [freerdp 安装目录]/lib/cmake/FreeRDP2
    • FreeRDP-Client_DIR: [freerdp 安装目录]/lib/cmake/FreeRDP-Client2
    • BUILD_RABBITVNC: 编译 RabbitVNC 插件。默认为 ON
    • RabbitVNC_DIR: [RabbitVNC 安装目录]/lib/cmake/RabbitVNC
    • BUILD_TigerVNC: 编译 TigerVNC。默认为 ON
    • tigervnc_DIR: [TigerVNC 安装目录]/lib/cmake/tigervnc
    • BUILD_LibVNCServer: 编译 LibVNCServer。默认为 ON
    • LibVNCServer_DIR: [libvncserver 安装目录]/lib/cmake/LibVNCServer
    • LibDataChannel_DIR: [libdatachannel 安装目录]/lib/cmake/LibDataChannel
    • QXmpp_DIR=[QXmpp 安装目录]/lib/cmake/qxmpp
    • qtermwidget5_DIR: [qtermwidget 安装目录]/lib/cmake/qtermwidget5
    • libssh_DIR: [libssh 安装目录]/lib/cmake/libssh
    • QtService_DIR: [QtService 安装目录]/lib/cmake/QtService
  • 如果使用 vcpkg,增加下面参数

    • CMAKE_TOOLCHAIN_FILE: [vcpkg installation path]/scripts/buildsystems/vcpkg.cmake
    • VCPKG_MANIFEST_FEATURES: vcpkg 中的清单功能
  • 编译

    • 命令行编译

      • 不用 vcpkg

        ~$ cd RabbitRemoteControl
        ~/RabbitRemoteControl$ mkdir build
        ~/RabbitRemoteControl/build$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=`pwd`/install 
        ~/RabbitRemoteControl/build$ cmake --build . --config Release --target install
        
      • 使用 vcpkg

        ~$ cd RabbitRemoteControl
        ~/RabbitRemoteControl$ mkdir build
        ~/RabbitRemoteControl/build$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=`pwd`/install [可选依赖库] -DCMAKE_TOOLCHAIN_FILE=[vcpkg installation path]/scripts/buildsystems/vcpkg.cmake
        ~/RabbitRemoteControl/build$ cmake --build . --config Release --target install
        
    • IDE(Qt Creator) 编译

      • 打开项目: “菜单→文件→打开文件或项目”,选择项目根目录中的 CMakeLists.txt
      • 配置:点左侧工具栏上的 “项目→构建与运行”,配置 CMake 参数
        • 如果要安装,还需要 “项目→构建与运行→构建步骤→目标” 中,选中 install
      • 编译与运行: 点左侧工具栏上的 “开始调试” 或者按快捷键 “F5”
      • 如果用 vcpkg: 选项→Kits→Cmake Configureration: 增加 CMAKE_TOOLCHAIN_FILE=[vcpkg installation path]/scripts/buildsystems/vcpkg.cmake
    • 使用脚本 build_debpackage.sh

      • 设置编译本项目 → CMake 参数为环境变量。例如:

        export RabbitVNC_DIR=[RabbitVNC 安装目录]/lib/cmake/RabbitVNC
        export tigervnc_DIR=[TigerVNC 安装目录]/lib/cmake/tigervnc
        export QtService_DIR=[QtService 安装目录]/lib/cmake/QtService
        
      • 使用脚本 build_debpackage.sh

        ./build_debpackage.sh [$QT_ROOT] [$RabbitCommon_ROOT]
        
  • 运行

    • 程序安装在 install/bin 下

      ~$ cd RabbitRemoteControl
      ~/RabbitRemoteControl$ cd build/install/bin
      ~/RabbitRemoteControl$ ./RabbitRemoteControl.sh
      

    注意: 如果插件没有加载。则可能是插件的依赖库没有安装到系统。 你可以把依赖库的目录加入到环境变量 PKG_CONFIG_PATH 中。 你也可以把依赖库的目录加入到 /etc/ld.so.conf 文件中,然后运行 ldconfig 把依赖库加入到系统中。

  • Qt 变量

    • QT_DEBUG_PLUGINS: 调试插件

      export QT_DEBUG_PLUGINS=1

    • QT_QPA_PLATFORM: 加载指定的平台。例如使用 vnc

      export QT_QPA_PLATFORM=vnc
      

编译

Ubuntu

```bash
# 安装开发工具软件包
~$ sudo apt install build-essential
# 安装工具
~$ sudo apt install git cmake debhelper doxygen
# [可选] 安装 Qt5
~$ sudo apt install qttools5-dev qttools5-dev-tools qtbase5-dev \
    qtbase5-dev-tools qtmultimedia5-dev qtlocation5-dev libqt5svg5-dev \
    libqtermwidget5-0-dev
# 安装 X 开发库
~$ sudo apt install libxkbcommon-dev libxkbcommon-x11-dev libx11-xcb-dev \
    libx11-dev libxfixes-dev
~$ sudo apt install libutf8proc-dev libpam0g-dev #编译 qtermwidget 需要
# 安装依赖库
~$ sudo apt install freerdp2-dev libvncserver-dev libssh-dev libtelnet-dev
~$ sudo apt install debhelper fakeroot
# 安装 pixman ,RabbitVNC 和 TigerVNC 需要它
~$ sudo apt install libpixman-1-dev
# 编译 RabbitVNC
~$ git clone https://github.com/KangLin/RabbitVNC.git
~$ cd RabbitVNC
~$ mkdir build
~/RabbitVNC/build$ cmake .. -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=`pwd`/install
~/RabbitVNC/build$ cmake --build . --config Release --target install
~/RabbitVNC/build$ cd ~
# 编译 TigerVNC
~$ git clone https://github.com/KangLin/tigervnc.git
~$ cd tigervnc
~$ mkdir build
~/tigervnc/build$ cmake .. -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=`pwd`/install
~/tigervnc/build$ cmake --build . --config Release --target install
~/tigervnc/build$ cd ~
~$ sudo apt install libqxmpp-dev
# 编译 libdatachannel
~$ git clone https://github.com/paullouisageneau/libdatachannel.git
~$ cd libdatachannel
~/libdatachannel$ git submodule update --init --recursive
~/libdatachannel$ mkdir build
~/libdatachannel$ cd build
~/libdatachannel/build$ cmake .. -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=`pwd`/install
~/libdatachannel/build$ cmake --build . --config Release --target install
~/libdatachannel/build$ cd ~
# 编译 QtService
~$ git clone https://github.com/KangLin/qt-solutions.git
~$ cd qt-solutions/qtservice
~/qt-solutions/qtservice$ mkdir build
~/qt-solutions/qtservice$ cd build
~/qt-solutions/qtservice/build$ cmake .. -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=`pwd`/install
~/qt-solutions/qtservice/build$ cmake --build . --config Release --target install
~/qt-solutions/qtservice/build$ cd ~
~$ git clone https://github.com/KangLin/RabbitCommon.git
~$ git clone https://github.com/KangLin/RabbitRemoteControl.git
~$ cd RabbitRemoteControl
~/RabbitRemoteControl$ mkdir build
~/RabbitRemoteControl$ cd build
~/RabbitRemoteControl/build$ cmake .. -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=`pwd`/install \
    -DBUILD_FREERDP=ON \
    -DRabbitVNC_DIR=~/RabbitVNC/build/install/lib/cmake/RabbitVNC \
    -Dtigervnc_DIR=~/tigervnc/build/install/lib/cmake/tigervnc \
    -DLibDataChannel_DIR=~/libdatachannel/build/install/lib/cmake/LibDataChannel \
    -DQtService_DIR=~/qt-solutions/qtservice/build/lib/cmake/QtService
~/RabbitRemoteControl/build$ cmake --build . --config Release --target install
```

参见:编译集成

  • 编译

    ~/RabbitRemoteControl/build$ cmake .. \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMARK_SHARED=OFF \
        -DCMARK_TESTS=OFF \
        -DCMARK_STATIC=ON \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DBUILD_QUIWidget=OFF \
        -DBUILD_APP=ON \
        -DBUILD_FREERDP=ON
    cmake --build . --parallel $(nproc)
    cmake --install . --config Release --component DependLibraries --prefix AppDir/usr
    cmake --install . --config Release --component Runtime --prefix AppDir/usr
    cmake --install . --config Release --component Application --prefix AppDir/usr
    cmake --install . --config Release --component Plugin --prefix AppDir/usr
    
  • 建立

    # See: https://github.com/linuxdeploy/linuxdeploy-plugin-qt
    #export QMAKE=${QT_ROOT}/bin/qmake
    export EXTRA_PLATFORM_PLUGINS="libqxcb.so"
    # Icons from theme are not displayed in QtWidgets Application: https://github.com/linuxdeploy/linuxdeploy-plugin-qt/issues/17
    export EXTRA_QT_MODULES="svg"
    ./linuxdeploy-`uname -m`.AppImage --appdir=AppDir -v0 \
        --deploy-deps-only=AppDir/usr/plugins/Client \
        --deploy-deps-only=AppDir/usr/lib/`uname -m`-linux-gnu \
        --plugin qt \
        --output appimage
    
  • 运行

    sudo chmod u+x ./Rabbit_Remote_Control-`uname -m`.AppImage
    ./Rabbit_Remote_Control-`uname -m`.AppImage
    
  • 其它

    • 解压 AppImage

      ./Rabbit_Remote_Control-`uname -m`.AppImage --appimage-extract # 解压 AppImage 文件
      
    • FUSE 问题

      第一次执行AppImage文件的时候可能会碰到 PUSE 相关的问题,报错如下:

      dlopen(): error loading libfuse.so.2
      
      AppImages require FUSE to run.
      You might still be able to extract the contents of this AppImage
      if you run it with the --appimage-extract option.
      See https://github.com/AppImage/AppImageKit/wiki/FUSE
      
      for more information
      

      解决方案: 安装fuse2 sudo apt install fuse

snap
  • 编译:

    • Parts 生命周期: https://snapcraft.io/docs/parts-lifecycle

    • https://snapcraft.io/docs/how-snapcraft-builds

      ~$ git clone https://github.com/KangLin/RabbitRemoteControl.git
      ~$ cd RabbitRemoteControl
      ~$ snapcraft -v 
      

      这些生命周期步骤中的每一个都可以从命令行运行, 并且该命令可以是特定于部件的命令,也可以是应用于项目中的所有部件的命令。

      snapcraft pull [<part-name>]
      snapcraft build [<part-name>]
      snapcraft stage [<part-name>]
      snapcraft prime [<part-name>]
      snapcraft pack or snapcraft
      
    • 迭代构建: https://snapcraft.io/docs/iterating-over-a-build 通过以下命令,您可以单步执行此封装环境:

      • --shell:将快照构建到指定之前的生命周期步骤,并在环境中打开一个 shell 例如,运行 snapcraft prime [] --shell 将运行到暂存步骤并打开一个 shell)。

      • --shell-after:构建对指定生命周期步骤的快照,并在环境中打开 shell。 (例如,运行 snapcraft prime [] --shell-after 将运行到 prime 步骤,然后进入 shell)。

      • --debug 在发生错误后在环境中打开一个 shell。

        $ # 例如 prime freerdp
        $ snapcraft prime freerdp --shell-after -v --debug
        
    • 清理编译

      snapcraft clean
      
  • 调试

    • 开发模式安装 (--devmode)。未签名的。

      snap install ./rabbitremotecontrol_0.0.27_amd64.snap --devmode 
      
    • 运行

      rabbitremotecontrol
      
    • 卸载

      snap remove rabbitremotecontrol