交叉编译gstreamer-0.10.24

最近要在arm平台上使用gstreamer,于是开始了gstreamer的交叉编译。实现交叉编译有两种方式:

1. 在pc平台编译,利用ubuntu平台上的arm-linux-系列工具进行编译,此方式编译速度快,但是configure的交叉配置项设置很麻烦

2. 在目标平台编译,直接在目标板上用目标gcc工具进行编译,此方式编译速度慢,但是configure配置很简单,和pc机上的configure配置基本一样。

 

下面为pc平台的编译,还有错误

$GLIB_CFLAGS="-I/home/soeasy/nfsroot/target/usr/include/glib-2.0 -I/home/soeasy/nfsroot/target/usr/lib/glib-2.0/include" GLIB_LIBS="-L/home/soeasy/nfsroot/target/usr/lib/" XML_CFLAGS="-I/home/soeasy/nfsroot/target/usr/include/libxml2 "  GLIB_ONLY_CFLAGS=" -I/home/soeasy/nfsroot/target/usr/include/glib-2.0 -I/home/soeasy/nfsroot/target/usr/lib/glib-2.0/include  " ./configure --host=arm-linux --disable-nls --disable-static --disable-loadsave --with-html-dir=/tmp/dump --prefix=/home/soeasy/nfsroot/gstreamer/install LDFLAGS="-Wl,-rpath-link,/home/soeasy/nfsroot/target -lglib-2.0  -lgobject-2.0 -lgthread-2.0 -lgmodule-2.0 -lxml2 " CFLAGS="-I/home/soeasy/nfsroot/target/usr/include -I/home/soeasy/nfsroot/target/usr/include/glib-2.0 -I/home/soeasy/nfsroot/target/usr/lib/glib-2.0/include"

链接是提示下列错误:

arm-linux-gcc -shared  .libs/libgstreamer_0.10_la-glib-compat.o /
.libs/libgstreamer_0.10_la-gst.o .libs/libgstreamer_0.10_la-gstobject.o .libs/libgstreamer_0.10_la-gstbin.o /
.libs/libgstreamer_0.10_la-gstbuffer.o .libs/libgstreamer_0.10_la-gstbus.o .libs/libgstreamer_0.10_la-gstcaps.o /
.libs/libgstreamer_0.10_la-gstchildproxy.o .libs/libgstreamer_0.10_la-gstclock.o .libs/libgstreamer_0.10_la-gstelement.o /
.libs/libgstreamer_0.10_la-gstelementfactory.o .libs/libgstreamer_0.10_la-gsterror.o .libs/libgstreamer_0.10_la-gstevent.o /
.libs/libgstreamer_0.10_la-gstfilter.o .libs/libgstreamer_0.10_la-gstformat.o .libs/libgstreamer_0.10_la-gstghostpad.o /
.libs/libgstreamer_0.10_la-gstindex.o .libs/libgstreamer_0.10_la-gstindexfactory.o .libs/libgstreamer_0.10_la-gstinfo.o /
.libs/libgstreamer_0.10_la-gstinterface.o .libs/libgstreamer_0.10_la-gstiterator.o .libs/libgstreamer_0.10_la-gstmessage.o /
.libs/libgstreamer_0.10_la-gstminiobject.o .libs/libgstreamer_0.10_la-gstpad.o .libs/libgstreamer_0.10_la-gstpadtemplate.o /
.libs/libgstreamer_0.10_la-gstpipeline.o .libs/libgstreamer_0.10_la-gstplugin.o .libs/libgstreamer_0.10_la-gstpluginfeature.o /
.libs/libgstreamer_0.10_la-gstquery.o .libs/libgstreamer_0.10_la-gstregistry.o .libs/libgstreamer_0.10_la-gstsegment.o /
.libs/libgstreamer_0.10_la-gststructure.o .libs/libgstreamer_0.10_la-gstsystemclock.o .libs/libgstreamer_0.10_la-gsttaglist.o /
.libs/libgstreamer_0.10_la-gsttagsetter.o .libs/libgstreamer_0.10_la-gsttask.o .libs/libgstreamer_0.10_la-gsttrace.o /
.libs/libgstreamer_0.10_la-gsttypefind.o .libs/libgstreamer_0.10_la-gsttypefindfactory.o .libs/libgstreamer_0.10_la-gsturi.o /
.libs/libgstreamer_0.10_la-gstutils.o .libs/libgstreamer_0.10_la-gstvalue.o .libs/libgstreamer_0.10_la-gstparse.o /
.libs/libgstreamer_0.10_la-gstregistryxml.o .libs/libgstreamer_0.10_la-gstenumtypes.o .libs/libgstreamer_0.10_la-gstmarshal.o /
-Wl,--whole-archive parse/.libs/libgstparse.a -Wl,--no-whole-archive  -lm -lz -lpthread -ldl /
/usr/lib/libgobject-2.0.so /usr/lib/libgthread-2.0.so -lrt /usr/lib/libgmodule-2.0.so /usr/lib/libglib-2.0.so /usr/lib/libxml2.so  /
-Wl,-rpath-link -Wl,/home/soeasy/nfsroot/target -pthread -Wl,--export-dynamic -Wl,-soname -Wl,libgstreamer-0.10.so.0 /
-Wl,-version-script -Wl,.libs/libgstreamer-0.10.ver -o .libs/libgstreamer-0.10.so.0.7.0

 

/usr/lib/libgobject-2.0.so: could not read symbols: File in wrong format

 

显然需要链接的库libgobject-2.0.so没有定位到交叉库的目录,而是定位了pc机本身的i686的库,链接不成功。

根据gcc的参数说明,我在configure时指定了

LDFLAGS="-Wl,-rpath-link,/home/soeasy/nfsroot/target -lglib-2.0  -lgobject-2.0 -lgthread-2.0 -lgmodule-2.0 -lxml2 "

但是还是出错,郁闷

 

----------------------------------------------------------------------------------------------------------------------------------

继续交叉编译的工作,看来-Wl,-rpath-link,/home/soeasy/nfsroot/target是不能解决问题了,开始试试其他参数。

$LDFLAGS=" --sysroot=/home/soeasy/nfsroot/target -lglib-2.0 -lgobject-2.0 -lgthread-2.0 -lgmodule-2.0 -lxml2 " CPPFLAGS="-I/home/soeasy/nfsroot/target/usr/include -I/home/soeasy/nfsroot/target/usr/include/glib-2.0 -I/home/soeasy/nfsroot/target/usr/lib/glib-2.0/include -I/home/soeasy/nfsroot/target/usr/include/libxml2" GLIB_CFLAGS="-I/home/soeasy/nfsroot/target/usr/include/glib-2.0 -I/home/soeasy/nfsroot/target/usr/lib/glib-2.0/include" GLIB_LIBS="-L/home/soeasy/nfsroot/target/usr/lib --sysroot=/home/soeasy/nfsroot/target -lglib-2.0 -lgobject-2.0 -lgthread-2.0 -lgmodule-2.0 -lxml2" GLIB_ONLY_CFLAGS=" -I/home/soeasy/nfsroot/target/usr/include/glib-2.0 -I/home/soeasy/nfsroot/target/usr/lib/glib-2.0/include  " GLIB_ONLY_LIBS="-L/home/soeasy/nfsroot/target/usr/lib/ --sysroot=/home/soeasy/nfsroot/target -lglib-2.0 -lgobject-2.0 -lgthread-2.0 -lgmodule-2.0 -lxml2" ./configure --prefix=/install --disable-debug --disable-valgrind --host=arm-linux XML_CFLAGS="-I/home/soeasy/nfsroot/target/usr/include/libxml2"  GST_ALL_CFLAGS="-I/home/soeasy/nfsroot/target/usr/include -I/home/soeasy/nfsroot/target/usr/include/glib-2.0 -I/home/soeasy/nfsroot/target/usr/lib/glib-2.0/include -I/home/soeasy/nfsroot/target/usr/include/libxml2"

 

这次看来libgobject-2.0.so是链接成功了,但是又出现下列错误:

libtool: link:  arm-linux-gcc -shared  .libs/libgstreamer_0.10_la-gst.o .libs/libgstreamer_0.10_la-gstobject.o .libs/libgstreamer_0.10_la-gstbin.o .libs/libgstreamer_0.10_la-gstbuffer.o .libs/libgstreamer_0.10_la-gstbufferlist.o .libs/libgstreamer_0.10_la-gstbus.o .libs/libgstreamer_0.10_la-gstcaps.o .libs/libgstreamer_0.10_la-gstchildproxy.o .libs/libgstreamer_0.10_la-gstclock.o .libs/libgstreamer_0.10_la-gstdebugutils.o .libs/libgstreamer_0.10_la-gstelement.o .libs/libgstreamer_0.10_la-gstelementfactory.o .libs/libgstreamer_0.10_la-gsterror.o .libs/libgstreamer_0.10_la-gstevent.o .libs/libgstreamer_0.10_la-gstfilter.o .libs/libgstreamer_0.10_la-gstformat.o .libs/libgstreamer_0.10_la-gstghostpad.o .libs/libgstreamer_0.10_la-gstindex.o .libs/libgstreamer_0.10_la-gstindexfactory.o .libs/libgstreamer_0.10_la-gstinfo.o .libs/libgstreamer_0.10_la-gstinterface.o .libs/libgstreamer_0.10_la-gstiterator.o .libs/libgstreamer_0.10_la-gstmessage.o .libs/libgstreamer_0.10_la-gstminiobject.o .libs/libgstreamer_0.10_la-gstpad.o .libs/libgstreamer_0.10_la-gstpadtemplate.o .libs/libgstreamer_0.10_la-gstparamspecs.o .libs/libgstreamer_0.10_la-gstpipeline.o .libs/libgstreamer_0.10_la-gstplugin.o .libs/libgstreamer_0.10_la-gstpluginfeature.o .libs/libgstreamer_0.10_la-gstpoll.o .libs/libgstreamer_0.10_la-gstpreset.o .libs/libgstreamer_0.10_la-gstquark.o .libs/libgstreamer_0.10_la-gstquery.o .libs/libgstreamer_0.10_la-gstregistry.o .libs/libgstreamer_0.10_la-gstsegment.o .libs/libgstreamer_0.10_la-gststructure.o .libs/libgstreamer_0.10_la-gstsystemclock.o .libs/libgstreamer_0.10_la-gsttaglist.o .libs/libgstreamer_0.10_la-gsttagsetter.o .libs/libgstreamer_0.10_la-gsttask.o .libs/libgstreamer_0.10_la-gsttaskpool.o .libs/libgstreamer_0.10_la-gsttrace.o .libs/libgstreamer_0.10_la-gsttypefind.o .libs/libgstreamer_0.10_la-gsttypefindfactory.o .libs/libgstreamer_0.10_la-gsturi.o .libs/libgstreamer_0.10_la-gstutils.o .libs/libgstreamer_0.10_la-gstvalue.o .libs/libgstreamer_0.10_la-gstparse.o .libs/libgstreamer_0.10_la-gstregistrybinary.o .libs/libgstreamer_0.10_la-gstxml.o .libs/libgstreamer_0.10_la-gstenumtypes.o .libs/libgstreamer_0.10_la-gstmarshal.o  -Wl,--whole-archive parse/.libs/libgstparse.a -Wl,--no-whole-archive  -Wl,-rpath -Wl,/home/soeasy/nfsroot/target/usr/lib -Wl,-rpath -Wl,/home/soeasy/nfsroot/target/usr/lib -L/home/soeasy/nfsroot/target/usr/lib /home/soeasy/nfsroot/target/usr/lib/libgobject-2.0.so /home/soeasy/nfsroot/target/usr/lib/libgthread-2.0.so -lpthread -lrt /home/soeasy/nfsroot/target/usr/lib/libgmodule-2.0.so /home/soeasy/nfsroot/target/usr/lib/libglib-2.0.so /home/soeasy/nfsroot/target/usr/lib/libxml2.so -lm -lz -ldl    -Wl,-soname -Wl,libgstreamer-0.10.so.0 -Wl,-version-script -Wl,.libs/libgstreamer-0.10.ver -o .libs/libgstreamer-0.10.so.0.21.0
/opt/mv_pro_5.0/montavista/pro/devkit/arm/v5t_le/bin/../lib/gcc/armv5tl-montavista-linux-gnueabi/4.2.0/../../../../armv5tl-montavista-linux-gnueabi/bin/ld: skipping incompatible /lib/libpthread.so.0 when searching for /lib/libpthread.so.0
/opt/mv_pro_5.0/montavista/pro/devkit/arm/v5t_le/bin/../lib/gcc/armv5tl-montavista-linux-gnueabi/4.2.0/../../../../armv5tl-montavista-linux-gnueabi/bin/ld: cannot find /lib/libpthread.so.0
collect2: ld returned 1 exit status

 

看来又找到本机系统的库目录里去了。

 仔细分析最后的链接命令,原来是用libtool工具来进行的。由于所有的Makefile文件是通过config.status产生的,想想link的命令肯定在

此文件里,于是编辑config.status,查找shared,看相关的脚本。搜索到下列:

archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
     cat $export_symbols | sed -e "s//(.*/)//1;/" >> $output_objdir/$libname.ver~
     echo "local: *; };" >> $output_objdir/$libname.ver~
     $CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'

 

好了,动手改起来,添加上--sysroot=/home/soeasy/nfsroot/target,变成下面这样

archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags --sysroot=/home/soeasy/nfsroot/target ${wl}-soname $wl$soname -o $lib'
archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
     cat $export_symbols | sed -e "s//(.*/)//1;/" >> $output_objdir/$libname.ver~
     echo "local: *; };" >> $output_objdir/$libname.ver~
     $CC -shared $libobjs $deplibs $compiler_flags --sysroot=/home/soeasy/nfsroot/target ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'

保存后,执行

#make

一切ok

 

编译gstreamer-0.10.24时需要高版本的glib库,所以编译了glib-2.20.4,步骤如下

直接./configure --prefix=/install --host=arm-linux 出错,需要预先定义变量,利用cache file实现

$echo glib_cv_stack_grows=no >> cache.file
$echo glib_cv_uscore=no >> cache.file
$echo ac_cv_func_posix_getpwuid_r=no >> cache.file
$echo ac_cv_func_posix_getgrgid_r=no >> cache.file
$./configure --prefix=/install --host=arm-linux --cache-file=cache.file

 

编译中同样会遇到gstreamer同样的问题,修改config.status,在类似的shared命令里添加--sysroot,然后ok

 

通过测试gst代码。

 

#include #include GstElement *play_bin; GstElement *pipeline; static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data) { GMainLoop *loop = (GMainLoop *) data;//这个是主循环的指针,在接受EOS消息时退出循环 switch (GST_MESSAGE_TYPE(msg)) { default: break; } return TRUE; } void print_version() { const gchar *nano_str; guint major, minor, micro, nano; gst_version (&major, &minor, µ, &nano); if (nano == 1) nano_str = "(CVS)"; else if (nano == 2) nano_str = "(Prerelease)"; else nano_str = ""; g_print ("This program is linked against GStreamer %d.%d.%d %s/n", major, minor, micro, nano_str); } int main (int argc, char *argv[]) { GMainLoop *loop; GstElement *source,*decoder,*sink;//定义组件 GstBus *bus; if(!g_thread_supported()) g_thread_init(NULL); gst_init (&argc, &argv); print_version(); loop = g_main_loop_new(NULL,FALSE); pipeline = gst_pipeline_new("audio-player"); play_bin = gst_element_factory_make("playbin","play_bin"); bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); g_object_set(G_OBJECT(play_bin),"uri",argv[1],NULL); gst_bus_add_watch(bus, bus_call, loop); gst_object_unref(bus); gst_bin_add_many(GST_BIN(pipeline), play_bin, NULL); g_print("Running.../n"); gst_element_set_state(pipeline,GST_STATE_PLAYING); g_main_loop_run (loop); gst_element_set_state(pipeline,GST_STATE_NULL); gst_object_unref(GST_OBJECT(pipeline)); return 0; }

 

$arm-linux-gcc --sysroot=/home/soeasy/nfsroot/target/ -I /home/soeasy/nfsroot/target/usr/include/gstreamer-0.10/ -I /home/soeasy/nfsroot/target/usr/include/glib-2.0/ -I /home/soeasy/nfsroot/target/usr/lib/glib-2.0/include/ -I /home/soeasy/nfsroot/target/usr/include/libxml2/  -pthread -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lxml2 -lglib-2.0   test-gst.c -otest

 

 

 

你可能感兴趣的:(交叉编译gstreamer-0.10.24)