抄袭自:ubuntu16.04 利用Docker 部署C++ Gui项目(OpenCV PCL动态库集成) - zzc_bjergsen - 博客园 (cnblogs.com)
- 打包脚本已经验证过了
ldd.shfunction useage() { cat << EOU Useage: bash $0 <path to the binary> <path to copy the dependencies> EOU exit 1 } #Validate the inputs [[ $# < 2 ]] && useage #Check if the paths are vaild [[ ! -e $1 ]] && echo "Not a vaild input $1" && exit 1 [[ -d $2 ]] || echo "No such directory $2 creating..."&& mkdir -p "$2" #Get the library dependencies echo "Collecting the shared library dependencies for $1..." deps=$(ldd $1 | awk 'BEGIN{ORS=" "}$1\ ~/^\//{print $1}$3~/^\//{print $3}'\ | sed 's/,$/\n/') echo "Copying the dependencies to $2" #Copy the deps for dep in $deps do echo "Copying $dep to $2" cp "$dep" "$2" done echo "Done!"- 使用
ldd.sh yourexe(可执行文件) des_path(目标文件夹) - 这个打包脚本牛批在于将链接对应的源文件也打包下来,只是名字仍沿用原来的链接名,
到目标机器上后改下目标机器的环境变量sudo vim /etc/bash.bashrc # 追加变量 export LD_LIBRARY_PATH=/home/zhima/projects/RailTrackPatrol:$LD_LIBRARY_PATH # 更新环境变量 source /etc/profile
- 启动脚本
run.sh注意,脚本最后一行要适应改成自己的软件名字path_curr=$(cd `dirname $0`; pwd) #dirname $0,取得当前执行的脚本文件的父目录 #cd `dirname $0`,进入这个目录(切换当前工作目录) #pwd,显示当前工作目录(cd执行后的) # add share lib path to system export PATH="${path_curr}:$PATH" export LD_LIBRARY_PATH="${path_curr}:$LD_LIBRARY_PATH" # print for debug #echo $LD_LIBRARY_PATH #ldd ./main # execute ./yourexename $prama1 $prama2 $3prama3 # $0 $1 $2 $3 is the parameters from Terminal