ushare是网络上一个DMS的源代码,下面要交叉编译到目标平台上:

编译环境:
编译器:arm-hisiv200-linux-gcc
主机:ubuntu 10.4

源码包:
ffmpeg-0.11.tar.bz2 
libdlna-0.2.4.tar.bz2 
libupnp-1.6.17.tar.bz2
ushare-1.1a.tar.bz2

依赖关系:
ushare 依赖libdlna,libupnp
libdlna依赖ffmpeg中的libavformat,libavcodec,libavutil

约定目录
WORK_DIR=$PWD
TARGET_INC="$WORK_DIR"/inc
TARGET_LIBS="$WORK_DIR"/lib
TARGET_BIN="$WORK_DIR"/bin
TARGET_SBIN="$WORK_DIR"/sbin

1.交叉编译upnp
./configure \
    --prefix="$WORK_DIR" \
    --bindir="$TARGET_BIN" \
    --sbindir="$TARGET_BIN" \
    --libexecdir="$TARGET_BIN" \
    --libdir="$TARGET_LIBS" \
    --includedir="$TARGET_INC" \
    --host="$CROSS_COMPILE" \
    --enable-debug \
    --enable-shared \
    --enable-static
make
make install

2.交叉编译ffmpeg
./configure \
    --prefix="$WORK_DIR" \
    --bindir="$TARGET_BIN" \
    --libdir="$TARGET_LIBS" \
    --incdir="$TARGET_INC" \
    --enable-small \
    --enable-shared \
    --disable-doc \
    --disable-yasm \
    --disable-ffmpeg \
    --disable-ffplay \
    --disable-ffserver \
    --disable-ffprobe \
    --disable-avdevice \
    --disable-swresample \
    --disable-swscale \
    --disable-postproc \
    --disable-avfilter \
    --disable-w32threads \
    --disable-os2threads \
    --cross-prefix="$CROSS_COMPILE-" \
    --target-os=linux \
    --arch=arm
make
make install

3.交叉编译libdlna
修改目录下的configure文件:
(1)修改
 639 if [ -n "$ffmpegdir" ]; then
     640   check_cflags -I$ffmpegdir
     641   check_ldflags -L$ffmpegdir
     642 fi

 644 echolog "Checking for libavformat ..."
 645 check_lib libavformat/avformat.h av_register_all -lavformat || die "Error, can't find libavformat !"
 646 echolog "Checking for libavcodec ..."
 647 check_lib libavcodec/avcodec.h avcodec_register_all -lavcodec || die "Error, can't find libavcodec !"
为:
 639 if [ -n "$ffmpegdir" ]; then
     640   check_cflags -I$ffmpegdir/inc
     641   check_ldflags -L$ffmpegdir/lib
    642 fi

 644 echolog "Checking for libavcodec ..."
 645 check_lib libavcodec/avcodec.h avcodec_register_all -lavcodec -lavutil || die "Error, can't find libavcodec !"
 646 echolog "Checking for libavformat ..."
 647 check_lib libavformat/avformat.h av_register_all -lavformat || die "Error, can't find libavformat !"
(2)修改:
 662 VERSION=`$TMPE`
为:
 662 VERSION=“0.2.4”

./configure \
    --prefix="$WORK_DIR" \
    --libdir="$TARGET_LIBS" \
    --includedir="$TARGET_INC" \
    --enable-shared \
    --with-ffmpeg-dir="$WORK_DIR" \
    --disable-developer \
    --enable-debug \
    --cross-prefix="$CROSS_COMPILE-" \
    --cross-compile
 
make
make install

4.交叉编译ushare
(1)修改configure:
 将TARGET_LIBS目录下的pkgconfig目录复制到/usr/local/lib目录下,因为ushare的configure要检查版本号,编译完了记得删除它。
 662   check_lib dlna.h dlna_register_all_media_profiles -ldlna|| die "Error, can't find libdlna (install it or use --disable-dlna) !"

 662   check_lib dlna.h dlna_register_all_media_profiles -ldlna -lavcodec -lavutil -lavformat || die "Error, can't find libdlna (install it or use --disable-dlna) !"
(2)vi src/ushare.c
 191   ip = request->CtrlPtIPAddr.s_addr;
TO 191   ip = ((struct in_addr*)&request->CtrlPtIPAddr)->s_addr;

 647 check_lib upnp/upnp.h UpnpSetMaxContentLength -lupnp || die "Error, can't find libupnp !"
TO  647 check_lib upnp/upnp.h UpnpSetMaxContentLength -lupnp -lixml || die "Error, can't find libupnp !"

./configure \
    --prefix="$WORK_DIR" \
    --bindir="$TARGET_BIN" \
    --log=yes \
    --localedir="$WORK_DIR" \
    --enable-dlna \
    --with-libupnp-dir="$WORK_DIR" \
    --with-libdlna-dir="$WORK_DIR" \
    --enable-debug \
    --cross-prefix="$CROSS_COMPILE-" \
    --cross-compile
cp config.h src/
make
make install

===============================================================
将程序放到开发板上运行,一直报错,UpnpInit函数返回-203
发现是绑定错误,定位错误到:
miniserver.c:get_miniserver_sockets:
 /* Bind to local socket. */
 memset(&stop_sockaddr, 0, sizeof (stop_sockaddr));
 stop_sockaddr.sin_family = (sa_family_t)AF_INET;
 stop_sockaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
 ret = bind(miniServerStopSock, (struct sockaddr *)&stop_sockaddr,
  sizeof(stop_sockaddr));
怀疑是开发板不支持127.0.0.1地址,在开发板上ping一下127.0.0.1,果然如此
在开发板上运行ifconfig lo 127.0.0.1就起来了,再运行,程序就起来了。

 

Logo

更多推荐