关闭

【笔记】Qt程序在Windows、OS X、CentOS、Ubuntu下的打包处理

910人阅读 评论(0) 收藏 举报
分类:

主程序名 web_transmit_adapter


Windows:

打包主目录windows:包含子目录web_transmit_adapter和两个打包文件web_transmit_adapter.nsi、和packing.bat

而在web_transmit_adapter子目录中包含了Qt程序web_transmit_adapter.exe以及一些依赖的第三方库文件等

发布Qt程序时,需要额外拷贝一些Qt库文件:

使用命令行可以拷贝需要依赖的Qt库文件,“C:\Qt\Qt5.5.1\5.5\msvc2010\bin\windeployqt.exe --release E:\CODES\yanrk\web_transmit_adapter\bin\windows\dll_release”


使用NSIS来做安装包,web_transmit_adapter.nsi内容如下:

; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "web_transmit_adapter"
!define PRODUCT_VERSION "2.0.16.824"
!define PRODUCT_PROTOCOL "RayvisionWeb"
!define PRODUCT_PUBLISHER "Shenzhen Rayvision Technology Co., Ltd."
!define PRODUCT_WEB_SITE "http://www.rayvision.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_STARTUP_KEY "Software\Microsoft\Windows\CurrentVersion\Run"

; MUI 1.67 compatible ------
!include "MUI.nsh"
!include "x64.nsh"
!include "WordFunc.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
!define MUI_COMPONENTSPAGE ;元件页面
; Directory page
!insertmacro MUI_PAGE_DIRECTORY

; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN_TEXT "$(StartProgram)"
!define MUI_FINISHPAGE_RUN "$INSTDIR\web_transmit_adapter.exe"
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "English"

; Set name using the normal interface (Name command)
LangString Name ${LANG_ENGLISH} "English"
LangString Name ${LANG_SIMPCHINESE} "简体中文"
LangString Title ${LANG_ENGLISH} "web_transmit_adapter"
LangString Title ${LANG_SIMPCHINESE} "web_transmit_adapter"
LangString Language ${LANG_ENGLISH} "english"
LangString Language ${LANG_SIMPCHINESE} "chinese"
LangString RemoveTip ${LANG_ENGLISH} "Has been successfully removed from your computer."
LangString RemoveTip ${LANG_SIMPCHINESE} "已成功地从你的计算机移除。"
LangString RunName ${LANG_ENGLISH} "web_transmit_adapter"
LangString RunName ${LANG_SIMPCHINESE} "web_transmit_adapter"
LangString RunExe ${LANG_ENGLISH} "web_transmit_adapter.exe"
LangString RunExe ${LANG_SIMPCHINESE} "web_transmit_adapter.exe"
LangString AlreadyInstall ${LANG_ENGLISH} "You already have an version of client installed,"
LangString AlreadyInstall ${LANG_SIMPCHINESE} "检测到本机已经安装了${PRODUCT_NAME},"
LangString InstallInfo ${LANG_ENGLISH} "Do you want to uninstall it before setup?"
LangString InstallInfo ${LANG_SIMPCHINESE} "是否先卸载已安装的版本?"
LangString StartProgram ${LANG_ENGLISH} "Start $(Title)"
LangString StartProgram ${LANG_SIMPCHINESE} "运行 $(Title)"

; First is default
;LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf"
;LoadLanguageFile "${NSISDIR}\Contrib\Language files\SimpChinese.nlf"

; MUI end ------

;Name "${PRODUCT_NAME} ${PRODUCT_VERSION} $(Name)"
Name "$(Title) ${PRODUCT_VERSION} $(Name)"
OutFile "..\..\release\web_transmit_adapter_setup.exe"
;RequestExecutionLevel admin ; user 或者 admin ;注册表需要管理员权限
InstallDir ""
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
AllowRootDirInstall true

Var lang
Function .onInit
    ReadRegStr $R0 HKLM ${PRODUCT_UNINST_KEY} "UninstallString"
    StrCmp $R0 "" done

    MessageBox MB_YESNOCANCEL|MB_ICONQUESTION  "$(AlreadyInstall) $\n$\n $(InstallInfo)" \
      /SD IDYES \
      IDYES uninstall \
      IDNO done
    Abort

uninstall:
    ClearErrors
    ExecWait '$R0 _?=$INSTDIR'
    ;Exec $INSTDIR\uninst.exe

done:
    ${If} ${RunningX64}
        StrCpy $InstDir "D:\Program Files (x86)"
    ${Else}
        StrCpy $InstDir "D:\Program Files"
    ${EndIf}

    Push Verdana
    Push 9
    ;Language selection dialog
    Push ""
    Push ${LANG_ENGLISH}
    Push English
    Push ${LANG_SIMPCHINESE}
    Push "Simplified Chinese"
    Push A ; A means auto count languages
           ; for the auto count to work the first empty push (Push "") must remain
    LangDLL::LangDialog "Installer Language" "Please select the language of the installer"

    Pop $LANGUAGE
    StrCmp $LANGUAGE "cancel" 0 +2
        Abort

    StrCmp $LANGUAGE ${LANG_SIMPCHINESE} 0 +2
        Strcpy $lang "china"
        Goto +2
        StrCpy $lang "english"
FunctionEnd

Var len1
Var len2
Var leni
Var len
Var sun
Var len3
Var len4
!macro ExeEnd  exestr
    strlen $sun "${exestr}"
    intop $len3 0 + 0
    intop $len4 0 + 0
    intop $len 0 + 0
    intop $leni 0 + 0
    strcmp $sun 0 +12 0                    ;是否到了字符串的尾端!
    IntOp $leni $leni + 1                  ;截取字符的长度增加!
    StrCpy $len1 "${exestr}" $leni $len3   ;截取字符,并保存与len1中
    StrCpy $len2 "$len1" "" -1             ;取出Len1最后一个字符放入Len2中
    Strcmp $len2 ";" 0 +9                  ;判断Len2中的字符是不是";"如果是,表示这以经是一个进程名了!如果不是,刚跳过下面的宏,继续取!              
    StrCpy $len $len1 -1
    FindProcDLL::FindProc "$len" ;查找进程是否存在!
    StrCmp $R0 1 0 +2
    KillProcDLL::KillProc "$len" ;杀掉进程,此处应注意,不是所有程序的进程都能杀掉,有些进程用这个方法无法结束!
    intop $leni 0 + 0
    strlen $len4 "$len1"
    intop $len3 $len3 + $len4
    strcpy $len1 ""
    IntOp $sun $sun - 1     ;字符串长度减1
    strcmp $sun 0 0 -13     ;此处判断字条串长度如果为0则到了尾端了!
    ;杀掉最后一个进程文件!
    FindProcDLL::FindProc "$len1" ;查找譔进程是否存在!
    StrCmp $R0 1 0 +2
    KillProcDLL::KillProc "$len1" ;杀掉进程,此处应注意,不是所有程序的进程都能杀掉,有些进程用这个方法无法结束!
!macroend

!define SHCNE_ASSOCCHANGED 0x08000000
!define SHCNF_IDLIST 0

Function RefreshShellIcons
    ; By jerome tremblay - april 2003
    System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v \
    (${SHCNE_ASSOCCHANGED}, ${SHCNF_IDLIST}, 0, 0)'
FunctionEnd

Section
    !insertmacro ExeEnd "web_transmit_adapter.exe;web_transmit_service.exe"
SectionEnd

Section "MainSection" SEC01
    ${WordFind} $INSTDIR "Rayvision\web_transmit_adapter" "*" $R0
    IntCmp $R0 0 0 +2 +2
    StrCpy $INSTDIR "$INSTDIR\Rayvision\web_transmit_adapter"

    SetOutPath "$INSTDIR"
    SetOverwrite on

    SetShellVarContext all
    Delete "$SMPROGRAMS\${PRODUCT_NAME}\$(RunName).lnk"
    Delete "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk"
    Delete "$DESKTOP\$(RunName).lnk"
    Delete "$INSTDIR\web_transmit_adapter.exe"
    Delete "$INSTDIR\web_transmit_service.exe"

    Call RefreshShellIcons

    CreateDirectory "$SMPROGRAMS"

    File /r ".\web_transmit_adapter\process_killer.exe"
    ExecWait '"process_killer.exe" "web_transmit_adapter.exe" "web_transmit_service.exe"'
    File /r ".\web_transmit_adapter\*"
SectionEnd

Section -AdditionalIcons
    ; WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
    ; CreateShortCut "$SMPROGRAMS\CRClient\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
    ; CreateShortCut "$SMPROGRAMS\Rayvision\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
    WriteUninstaller "$INSTDIR\uninst.exe"
    WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\$(RunExe)"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\$(RunExe)"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Installer Language" $LANGUAGE
    WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "FirstRun" 1
    WriteRegStr HKCU "${PRODUCT_STARTUP_KEY}" "${PRODUCT_NAME}" '"$INSTDIR\$(RunExe)"'
    WriteRegStr HKCR "${PRODUCT_PROTOCOL}" "" "web transmit adapter protocol"
    WriteRegStr HKCR "${PRODUCT_PROTOCOL}" "URL Protocol" "$INSTDIR\$(RunExe)"
    WriteRegStr HKCR "${PRODUCT_PROTOCOL}\DefaultIcon" "" "$INSTDIR\$(RunExe),1"
    WriteRegStr HKCR "${PRODUCT_PROTOCOL}\shell\open\command" "" '"$INSTDIR\$(RunExe)" "%1"'
SectionEnd

Function un.onUninstSuccess
    HideWindow
    MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) $(RemoveTip)"
FunctionEnd

Function un.onInit
    ReadRegStr $LANGUAGE HKLM "${PRODUCT_UNINST_KEY}" "Installer Language"
FunctionEnd

Section Uninstall
    !insertmacro ExeEnd "web_transmit_adapter.exe;web_transmit_service.exe"
    ExecWait '"process_killer.exe" "web_transmit_adapter.exe" "web_transmit_service.exe"'

    Delete "$SMPROGRAMS\${PRODUCT_NAME}\$(RunName).lnk"
    Delete "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk"
    Delete "$DESKTOP\$(RunName).lnk"

    ${WordFind} $INSTDIR "Rayvision\web_transmit_adapter" "*" $R0
    IntCmp $R0 0 0 +2 +2
    StrCpy $INSTDIR "$INSTDIR\Rayvision\web_transmit_adapter"

    Delete "$INSTDIR\*.*"
    RMDir /r "$INSTDIR"
    RMDir "$SMPROGRAMS\${PRODUCT_NAME}"

    SetShellVarContext all

    DeleteRegKey HKCR "${PRODUCT_PROTOCOL}"
    DeleteRegKey HKLM "${PRODUCT_UNINST_KEY}"
    DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
    DeleteRegValue HKCU "${PRODUCT_STARTUP_KEY}" "${PRODUCT_NAME}"
    SetAutoClose true
SectionEnd


使用脚本来简化打包过程,packing.bat内容如下:

"D:\Program Files\NSIS_Unicode\makensis.exe" .\web_transmit_adapter.nsi
pause
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe" sign /a ..\..\release\web_transmit_adapter_setup.exe
pause

双击packing.bat就可以在../../目录下找到安装包web_transmit_adapter_setup.exe




OS X:

打包主目录mac:包含子目录web_transmit_adapter和两个打包文件utility.sh、和packing.sh

而在web_transmit_adapter子目录中包含了OSX的程序包web_transmit_adapter.app以及“应用程序”的快捷方式(软连接?)

在web_transmit_adapter.app/Contents/MacOS下有Qt程序web_transmit_adapter以及一些依赖的第三方库文件等

发布Qt程序时,需要额外拷贝一些Qt库文件:

使用命令行可以拷贝需要依赖的Qt库文件,“~/Qt5.7.0/5.7/clang_64/bin/macdeployqt ./web_transmit_adapter/web_transmit_adapter.app”


辅助脚本utility.sh内容如下:

#!/bin/sh
rm -rf ./web_transmit_adapter/web_transmit_adapter.app/Contents/Frameworks
rm -rf ./web_transmit_adapter/web_transmit_adapter.app/Contents/PkgInfo
rm -rf ./web_transmit_adapter/web_transmit_adapter.app/Contents/PlugIns
rm -rf ./web_transmit_adapter/web_transmit_adapter.app/Contents/Resources
cp ../../cfg/* ./web_transmit_adapter/web_transmit_adapter.app/Contents/MacOS/
cp ../../res/* ./web_transmit_adapter/web_transmit_adapter.app/Contents/MacOS/
cp ../../../web_transmit_service/cfg/* ./web_transmit_adapter/web_transmit_adapter.app/Contents/MacOS/
$HOME/Qt5.7.0/5.7/clang_64/bin/macdeployqt ./web_transmit_adapter/web_transmit_adapter.app


使用命令行,“~/Qt5.7.0/5.7/clang_64/bin/macdeployqt ./web_transmit_adapter/web_transmit_adapter.app -dmg” 就可以完成打包,

但打包的程序不包含“应用程序的快捷方式”,等,所以,这里使用别的方式来打包,当然用系统的磁盘工具也是可以的。


使用脚本来简化打包过程(其实就是将磁盘工具打包脚本化),packing.sh内容如下:

#!/bin/sh

./utility.sh

log_file="/dev/null";
run_log()
{
    state_code=$?
    current_time=$(date +%Y/%m/%d" "%H:%M:%S)
    /bin/echo "$current_time [build dmg] state=[$state_code]:$1" >> $log_file
    /bin/echo "$2" >> $log_file 2>&1
}

version="2.0.16.824"

app_name="web_transmit_adapter"
src_dir="./web_transmit_adapter"
dst_dmg="../../release/web_transmit_adapter-$version.dmg"

if [ -e "$dst_dmg" ]; then
    rm -f "$dst_dmg"
fi

run_log src_dir=[$src_dir]

size=$(du -sh $src_dir)
size=$(echo $size | awk -F'[ ]' '{ printf $1 }')
unit=$(echo $size | awk '{ print substr($0, length($0), length($0)) }')
size=$(echo $size | awk '{ print substr($0, 0, length($0)-1) }')

if [ $unit = "G" ]; then
    size=$(echo $size | awk '{print $0*1024+103+10}')"M"
elif [ $unit = "M" ];then
    size=$(echo $size | awk '{print $0+10}')"M"
elif [ $unit = "K" ];then
    size=$(echo $size | awk '{print $0/1024+10}')"M"
elif [ $unit = "B" ];then
    size=$(echo $size | awk '{print $0/1024/1024+10}')"M"
fi

run_log [$size]

if [ -e "/Volumes/$app_name" ]; then
    hdiutil eject "/Volumes/$app_name" 2>&1
fi

cmd_res=$(hdiutil create -megabytes $size -fs HFS+ -volname "$app_name" temp_dmg 2>&1)
run_log "hdiutil create" "$cmd_res"

cmd_res=$(hdiutil mount temp_dmg.dmg 2>&1)
run_log "hdiutil mount" "$cmd_res"

cmd_res=$(ditto -rsrcFork "$src_dir" "/Volumes/$app_name" 2>&1)
run_log "ditto -rsrcFork" "$cmd_res"

cmd_res=$(hdiutil eject "/Volumes/$app_name" 2>&1)
run_log "hdiutil eject" "$cmd_res"

cmd_res=$(hdiutil convert temp_dmg.dmg -format UDZO -o "$dst_dmg" 2>&1)
run_log "hdiutil convert" "$cmd_res"

rm "temp_dmg.dmg"

执行packing.sh就可以在../../目录下找到安装包web_transmit_adapter_setup.dmg (但安装后,程序也不会出现在launchpad上,不知道为什么,磁盘工具打包也是)





CentOS:

打包主目录centos:包含子目录web_transmit_adapter和两个打包文件web_transmit_adapter.spec、和packing.sh

而在web_transmit_adapter子目录中包含了Qt程序web_transmit_adapter以及一些依赖的第三方库文件、以及Qt库文件等

linux下发布Qt程序时,Qt没有提供工具来额外拷贝一些Qt库文件,需要自己通过ldd命令去找依赖库


启动程序时,需要使用自身的库,而非系统的,所以,用脚本代替程序本身来启动

启动程序脚本web_transmit_adapter.sh内容如下:(必须和主程序同一层目录)

#!/bin/sh
appname=`basename $0 | sed s,\.sh$,,`

dirname=`dirname $0`
tmp="${dirname#?}"

if [ "${dirname%$tmp}" != "/" ]; then
    dirname=$PWD/$dirname
fi
LD_LIBRARY_PATH=$dirname:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
$dirname/$appname "$@"

用来从操作系统界面来启动程序的描述文件web_transmit_adapter.sh.desktop的内容如下:

[Desktop Entry]
GenericName=web transmit adapter
Name=web_transmit_adapter
Version=1.0.0
Exec=bash /usr/bin/web_transmit_adapter/web_transmit_adapter.sh
Comment=web transmit adapter on Linux x64
Icon=web_transmit_adapter.png
Type=Application
Terminal=false
StartupNotify=false
Encoding=UTF-8
Categories=Utility


使用命令行“yum -y install rpm-build”来安装rpmbuild,这是一个打包程序的命令行工具

rpmbuild打包时,需要一个.spec文件,它用来描述这个包

web_transmit_adapter.spec内容如下:

Name: web_transmit_adapter
Version: 2.0.16.824
Release: 1
Summary: web transmit adapter on Linux x86_64
Group: Applications/Productivity
License: GPL v3
Source0: %{name}.tar.gz
BuildArch: x86_64
BuildRoot: %{_tmppath}/%{name}-root
Packager: ryan <ryan@rayvision.com>
Url: [http://www.rayvision.com]
Vendor: Shenzhen Rayvision Technology Co., Ltd.
#Requires: libc6

%description
web transmit adapter on Linux x86_64

%prep
%setup -q -n %{name}

%build

%install
mkdir -p $RPM_BUILD_ROOT/usr/{bin,share}
mkdir -p $RPM_BUILD_ROOT/usr/bin/%{name}
mkdir -p $RPM_BUILD_ROOT/usr/bin/%{name}/platforms
mkdir -p $RPM_BUILD_ROOT/usr/share/{applications,pixmaps}
install %{name} $RPM_BUILD_ROOT/usr/bin/%{name}
install %{name}.sh $RPM_BUILD_ROOT/usr/bin/%{name}
install web_transmit_service $RPM_BUILD_ROOT/usr/bin/%{name}
install *.xml $RPM_BUILD_ROOT/usr/bin/%{name}
install *.ini $RPM_BUILD_ROOT/usr/bin/%{name}
install *.crt $RPM_BUILD_ROOT/usr/bin/%{name}
install *.key $RPM_BUILD_ROOT/usr/bin/%{name}
install libQt5* $RPM_BUILD_ROOT/usr/bin/%{name}
install libicu* $RPM_BUILD_ROOT/usr/bin/%{name}
install libq* $RPM_BUILD_ROOT/usr/bin/%{name}/platforms
install %{name}.desktop $RPM_BUILD_ROOT/usr/share/applications
install %{name}.png $RPM_BUILD_ROOT/usr/share/pixmaps

%files
%defattr(-,root,root)
%{_bindir}/%{name}/%{name}
%{_bindir}/%{name}/%{name}.sh
%{_bindir}/%{name}/web_transmit_service
%{_bindir}/%{name}/*.xml
%{_bindir}/%{name}/*.ini
%{_bindir}/%{name}/*.crt
%{_bindir}/%{name}/*.key
%{_bindir}/%{name}/libQt5*
%{_bindir}/%{name}/libicu*
%{_bindir}/%{name}/platforms/libq*
%{_datadir}/applications/%{name}.desktop
%{_datadir}/pixmaps/%{name}.png

%clean
rm -rf $RPM_BUILD_ROOT
rm -rf $RPM_BUILD_DIR

%changelog
* Wed Aug 24 2016 ryan
- Initial build


使用脚本来简化打包过程,packing.sh内容如下:

cp ../../../cfg/* ./web_transmit_adapter/
cp ../../../../web_transmit_service/cfg/* ./web_transmit_adapter/
rm -rf ~/rpm
mkdir -p ~/rpm/{BUILD,SOURCES,SPECS,SRPMS,RPMS}
cp ./web_transmit_adapter.spec ~/rpm/SPECS/
tar -zcvf ~/rpm/SOURCES/web_transmit_adapter.tar.gz ./web_transmit_adapter/
echo "%_topdir $HOME/rpm" > ~/.rpmmacros
rpmbuild -bb ~/rpm/SPECS/web_transmit_adapter.spec
cp ~/rpm/RPMS/x86_64/web_transmit_adapter*.rpm ../../release/
rm ../../release/*debug*.rpm

执行packing.sh就可以在../../目录下找到安装包web_transmit_adapter_setup.rpm






Ubuntu:

打包主目录ubuntu:包含子目录web_transmit_adapter和一个打包文件packing.sh

而在web_transmit_adapter子目录中包含了Qt程序web_transmit_adapter以及一些依赖的第三方库文件、以及Qt库文件等

linux下发布Qt程序时,Qt没有提供工具来额外拷贝一些Qt库文件,需要自己通过ldd命令去找依赖库


启动程序时,需要使用自身的库,而非系统的,所以,用脚本代替程序本身来启动

启动程序脚本web_transmit_adapter.sh内容如下:(必须和主程序同一层目录)

#!/bin/sh
appname=`basename $0 | sed s,\.sh$,,`

dirname=`dirname $0`
tmp="${dirname#?}"

if [ "${dirname%$tmp}" != "/" ]; then
    dirname=$PWD/$dirname
fi
LD_LIBRARY_PATH=$dirname:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
$dirname/$appname "$@"


用来从操作系统界面来启动程序的描述文件web_transmit_adapter.sh.desktop的内容如下:

[Desktop Entry]
GenericName=web transmit adapter
Name=web_transmit_adapter
Version=1.0.0
Exec=bash /usr/bin/web_transmit_adapter/web_transmit_adapter.sh
Comment=web transmit adapter on Linux x64
Icon=web_transmit_adapter.png
Type=Application
Terminal=false
StartupNotify=false
Encoding=UTF-8
Categories=Utility


ubuntu,我们用dpkg这个打包的命令行工具

dpkg打包时,需要一个control文件,它用来描述这个包

control内容如下:(注意,deb包的名字只能有字母和中划线,所以包名为web-transmit-adapter而非web_transmit_adapter)

Package: web-transmit-adapter
Priority: optional
Section: utils
Installed-Size: 65536
Maintainer: ryan <ryan@rayvision.com>
Architecture: i386
Version: 2.0.16.824
Depends: 
Description: web transmit adapter on Linux i386


deb包的文件必须是按安装路径来存放的,web_transmit_adapter目录结构如下(其中/usr那一层决定了用户安装后的结构):
web_transmit_adapter
     |
     |-- DEBIAN
     |    |-- control
     |
     |-- usr
          |-- bin
          |     |-- web_transmit_adapter
          |            |-- platforms
          |            |      |-- libqxcb.so  
          |            |
          |            |-- web_transmit_adapter
          |            |-- web_transmit_adapter.sh
          |            |-- libQt5Core.so.5 (and other .so files)
          |            |-- config.xml (and other configuration files)
          |-- share
                |-- applications
                |      |-- web_transmit_adapter.desktop
                |
                |-- pixmaps
                       |-- web_transmit_adapter.png


使用脚本来简化打包过程,packing.sh内容如下:

cp ../../../cfg/* ./web_transmit_adapter/usr/bin/web_transmit_adapter/
cp ../../../../web_transmit_service/cfg/* ./web_transmit_adapter/usr/bin/web_transmit_adapter/
file="./web_transmit_adapter/DEBIAN/control"
name="web_transmit_adapter"
eval $(awk '{ if ("Version:"==$1) { printf("version=%s", $2) } }' < $file)
release="1"
eval $(awk '{ if ("Architecture:"==$1) { printf("architecture=%s", $2) } }' < $file)
input="./web_transmit_adapter/"
output="../../release/$name-$version-$release.$architecture.deb"
dpkg -b $input $output

执行packing.sh就可以在../../目录下找到安装包web_transmit_adapter_setup.deb




其他笔记:

这次做Qt程序,以及安装包,记录一下需要知道的东西:

QT 编译问题:
    1. 编译不过,提示找不到文件、或者找不到链接符号,尝试清理掉生成的临时文件(如Makefiles等),QT自身的重新编译功能有问题;
    2. 注意shadow build和非shadow build的区别,切换时,可能也要删掉之前生成的临时文件再编译;

QT signal/slot不生效:
    1. connect(obj1, signal, obj2, slot)语句必须在QApplication application(argc, argv)之后执行;
    2. 有时候,函数的参数类型不能用引用类型,需要改成指针类型;

QT 运行时自动退出的问题:
    1. 在application.exec();前加入语句:application.setQuitOnLastWindowClosed(false);

防止僵尸进程:
    1. fork两次 + wait/waitpid
    2. 处理SIGCHLD信号
    3. 某个线程循环wait/waitpid

发布时,需要额外拷贝一些Qt的插件:
    1. windows:
            dll_debug: C:\Qt\Qt5.5.1\5.5\msvc2010\bin\windeployqt.exe --debug E:\CODES\yanrk\web_transmit_adapter\bin\windows\dll_debug
            dll_release: C:\Qt\Qt5.5.1\5.5\msvc2010\bin\windeployqt.exe --release E:\CODES\yanrk\web_transmit_adapter\bin\windows\dll_release
    2. mac:
            ~/Qt5.7.0/5.7/clang_64/bin/macdeployqt web_transmit_adapter.app
            ~/Qt5.7.0/5.7/clang_64/bin/macdeployqt web_transmit_adapter.app -dmg

websockets对浏览器的支持性问题:
    1. chrome基本没问题;
    2. QQ、360等以chrome为内核的也基本没问题;
    3. FireFox对证书做信任才行,可以先访问https://local.foxrenderfarm.com:9799/,提示之后,信任证书;
    4. IE,有的可以,有的不行;
    5. safari也可以,不过每次都要点击信任证书;
    6. 有时候需要关闭浏览器重新再打开一次才能建立连接;

查看依赖库:
    1. mac:otool -L application
    2. linux:ldd application
    3. windows:Depend工具

修改依赖库路径:
    1. mac:
            install_name_tool -id @executable_path/../SharedDylibs/libxyz.dylib /path/to/libxyz.dylib
            install_name_tool -change /path/to/libxyz.dylib @executable_path/../SharedDylibs/libxyz.dylib web_transmit_adapter

查看符号表:
    1. linux:objdump -tT libname.so | grep symbolname 或者 nm -D libname.so | grep symbolname

ubuntu(linux-x86)下的一些问题:
    1. 编译时,提示链接失败,此时需要给一些动态库做软连接,例如:ln -s /usr/lib/i386-linux-gnu/libcurl.so.4 /usr/lib/i386-linux-gnu/libcurl.so 等
    2. 运行时,提示找不到符号,最终发现:系统中的动态库版本是对的,但是在编译动态库本身时去掉了一些功能,故而没有那些符号,重新编译一个含有完整符号表的库即可

打包:
    1. windows用NSIS;
    2. mac用磁盘工具打包;
    3. linux-x64:
           用“yum -y install rpm-build”来安装rpmbuild;
           将工程中写好的rpm,.rpmmacros拷贝到用户根目录下(~/);
           确保.rpmmacros文件内容是对的;
           打包安装文件“tar -zcf web_transmit_adapter.tar.gz web_transmit_adapter”;
           将web_transmit_adapter.tar.gz拷入~/rpm/SOURCE/下;
           执行“rpmbuild -bb ~/rpm/SPECS/web_transmit_adapter.spec”
           在~/rpm/RPMS/下就有需要的.rpm文件生成
    4. linux-x86:
           按最终安装的模拟目录做好目录:web_transmit_adapter
           执行“dpkg -b ./web_transmit_adapter/ ./web_transmit_adapter.deb”

安装与卸载:
    1. linux-x64:
           安装:yum -y install /home/yanrk/Downloads/web_transmit_adapter_setup.rpm
           卸载:yum -y remove web_transmit_adapter
    2. linux-x86:
           安装:dpkg -i /home/yanrk/Downloads/web_transmit_adapter_setup.deb
           卸载:dpkg -r web-transmit-adapter(注:deb包名中不能包含下划线)

上面的linux-x64指的是linux x86_64,linux-x86指的是linux i386



参考了很多网上的资料,感谢:

http://doc.qt.io/qt-5/linux-deployment.html

http://doc.qt.io/qt-5/qtwebsockets-examples.html (QT websocket)

http://doc.qt.io/qt-5/osx-deployment.html 

http://blog.csdn.net/liuyez123/article/details/50462637

http://androidguy.blog.51cto.com/974126/1690306/

http://nick.luckygarden.org/rpath-loader_path-executable_path/ (@rpath, @loader_path, @executable_path 的区别)

http://jingyan.baidu.com/article/ff411625b9011212e48237b4.html (VMware11安装Mac OS X 10.10)

http://doc.qt.io/qt-5/linux-deployment.html

https://wiki.qt.io/Deploying_a_Qt5_Application_Linux (这个讲解了linux下的打包过程(rpm,deb))

http://blog.csdn.net/hjl_1991/article/details/50365927

http://blog.chinaunix.net/uid-16184599-id-3041024.html (deb包制作)

http://bbs.feng.com/read-htm-tid-6724285.html (dmg包制作)

http://www.macx.cn/thread-2099005-1-1.html (dmg包制作)

http://www.jianshu.com/p/379824922320 (脚本方式的dmg包制作)

https://lonesysadmin.net/2013/02/22/error-while-loading-shared-libraries-cannot-open-shared-object-file/

http://blog.csdn.net/xiliang_pan/article/details/38754077 (NSIS)



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:159846次
    • 积分:3303
    • 等级:
    • 排名:第10638名
    • 原创:167篇
    • 转载:10篇
    • 译文:0篇
    • 评论:41条
    文章分类
    最新评论