Supposed we have installed OpenCV on our local linux, the first thought is using a script to copying all shared libraries dependencies from local machine to target clusters. I used the great script "cpld" developed by Hemanth Copying shared library dependencies | Experiments on GNU/Linux:
#!/bin/bash
# Author : Hemanth.HM
# Email : hemanth[dot]hm[at]gmail[dot]com
# License : GNU GPLv3
#
function 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!"
However, the method will fail if the gcc complier on local machine is different from target cluster. Another method is to compile libraries on target machine.
1. Download OpenCV source code
2. Under the source folder, execute "mkdir release"
3. Run "cmake -D CMAKE_BUILD_TYPE=release .."
4. Verify the FFMPEG is suppored
5. make
P.S. In terms of FFMPEG, I used default libraries installed in the cluster to compile OpenCV. But while executing my program, I encounter the error of missing library "libavdevice.so". In order to sovle this issue, I have to re-compile FFMPEG-1.2, which required to link to additional libraries "libavfiler" and "libswresample" in the Makefile. I copied all FFMPEG libraries to the execution folder. Although OpenCV is compiled with older FFMPEG version (.so.52), it works fine with newer FFMPEG libraries (.so.54).
After complied, all the libraries will be put in opencv/release/lib. But since we don't have root right to install files, the include header files are not ready. To handle this issue, we need to copy our local OpenCV headers to the target machine:
scp -r /usr/lcoal/opencv user@target.com:/opencv/include/
scp -r /usr/lcoal/opencv2 user@target.com:/opencv/include/
To compile a program, we just need to assign the include and link paths of OpenCV in make file.
Finally, we need to export the library for dynamically link at runtime. (new FFMPEG are copied to current folder, so "." is also added to the PATH)
export LD_LIBRARY_PATH=.:opencv-2.4.5/release/lib
沒有留言:
張貼留言