Files
MyBlog/src/work/project-summary/智能巡视/tcpclienttester-打包与启动工作总结.md
T

4.0 KiB

icon, date, category, tag, title
icon date category tag title
mdi:lan-connect 2026-03-06
工作
项目总结
TCPClientTester
打包部署
Linux
TCPClientTester 打包与启动工作总结

TCPClientTester 打包与启动工作总结

TCPClientTester 打包与启动工作总结

本文整理了 TCPClientTester 在目标机器 10.6.221.8 的编译、打包、部署、启动验证及问题修复过程,用于后续复用与交接。


1. 背景与目标

  • 目标:在 10.6.221.8 上完成 TCPClientTester 的可独立运行打包。
  • 输出:桌面工具目录 /home/sunri/Desktop/tool,包含可执行程序、配置资源、依赖库和启动脚本。
  • 结果:通过 DISPLAY=:0 启动验证,程序可正常拉起。

2. 编译前准备

2.1 同步依赖目录

从参考机 10.6.220.186 同步 08_Preview 到目标机:

ssh 10.6.220.186 'tar czf - -C /home/sunri 08_Preview' | ssh 10.6.221.8 'tar xzf - -C /home/sunri'

2.2 环境变量

export PRJHOME=/home/sunri/IdeaProjects/V2.00
export CYGHOME=/home/sunri/08_Preview/linx80

3. 编译流程

cd /home/sunri/IdeaProjects/V2.00/src_cxx/99_TestTool/TCPClientTester
PRJHOME="$PRJHOME" CYGHOME="$CYGHOME" qmake TCPClientTester.pro
PRJHOME="$PRJHOME" CYGHOME="$CYGHOME" make -j4

编译产物:

  • /home/sunri/IdeaProjects/V2.00/binary/linx80/bin/tcptester

4. 打包目录规范

目标目录:/home/sunri/Desktop/tool

建议结构:

  • tool/bin/tcptester
  • tool/lib/(运行依赖库)
  • tool/config/(配置与资源)
  • tool/run_tcptester.sh(统一启动脚本)

5. 文件拷贝与依赖收集

5.1 程序与配置资源

TOOL=/home/sunri/Desktop/tool
SRC=/home/sunri/IdeaProjects/V2.00/src_cxx/99_TestTool/TCPClientTester
BIN=/home/sunri/IdeaProjects/V2.00/binary/linx80/bin/tcptester

rm -rf "$TOOL"
mkdir -p "$TOOL/bin" "$TOOL/lib" "$TOOL/config"

cp -f "$BIN" "$TOOL/bin/"
cp -f "$SRC/basic.xml" "$TOOL/config/"
cp -f "$SRC/TCPClientTester_zh_CN.qm" "$TOOL/config/"

for d in mainStationFile model res uploadFile lib "边缘节点一键测试" "巡视设备一键测试" "主站一键测试"; do
  [ -d "$SRC/$d" ] && cp -a "$SRC/$d" "$TOOL/config/"
done

5.2 依赖库自动拷贝

ldd "$BIN" | awk '/=> \/home\/sunri\// {print $3}' | sort -u | while read -r so; do
  cp -f "$so" "$TOOL/lib/"
done

6. 启动脚本与验证

6.1 启动脚本

cat > /home/sunri/Desktop/tool/run_tcptester.sh <<'EOF'
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
export LD_LIBRARY_PATH="$SCRIPT_DIR/lib:${LD_LIBRARY_PATH:-}"
export TCPCLIENTTESTER_LANG="${TCPCLIENTTESTER_LANG:-zh_CN}"
cd "$SCRIPT_DIR/config"
exec "$SCRIPT_DIR/bin/tcptester" "$@"
EOF

chmod +x /home/sunri/Desktop/tool/run_tcptester.sh

6.2 启动验证

env DISPLAY=:0 /home/sunri/Desktop/tool/run_tcptester.sh

持续运行验证(返回 124 表示进程在运行):

timeout 8s env DISPLAY=:0 /home/sunri/Desktop/tool/run_tcptester.sh
echo $?

7. 问题定位与修复

7.1 问题现象

  • 程序启动时在 CBasecfgManger::getLanguage() 处触发段错误(SIGSEGV)。

7.2 修复方案

  • 修改 main.cpp,避免调用崩溃路径。
  • 改为从环境变量读取语言:TCPCLIENTTESTER_LANG
  • 默认值设置为 zh_CN,保障无环境变量时可正常启动。

修复文件:

  • /home/sunri/IdeaProjects/V2.00/src_cxx/99_TestTool/TCPClientTester/main.cpp

8. 常用命令速查

中文启动:

/home/sunri/Desktop/tool/run_tcptester.sh

英文启动:

TCPCLIENTTESTER_LANG=en_US /home/sunri/Desktop/tool/run_tcptester.sh

检查缺失依赖:

ldd /home/sunri/Desktop/tool/bin/tcptester | grep "not found"

9. 交付结论

  • 已完成从编译到独立目录打包的全流程。
  • 启动脚本已固化依赖路径与语言参数,便于现场快速使用。
  • 崩溃问题已通过入口语言加载逻辑调整规避,当前版本可稳定启动。