qnx学习笔记-QNX系统glib-2.44交叉编译

来源:互联网 发布:php爱奇艺vip解析源码 编辑:程序博客网 时间:2024/05/20 19:18

锋影

e-mail 174176320@qq.com




QNX环境搭建完成了,准备编译几个常用的基础库,结果一不小心选了个最难的glib,大致的编译过程整理如下: 
1. 环境变量 
修改qnx660-env.sh,增加pkgconfig设置:

PKG_CONFIG_PATH="$QNX_TARGET/usr/lib/pkgconfig"PKG_CONFIG_SYSROOT_DIR="$QNX_TARGET"CC="arm-unknown-nto-qnx6.6.0eabi-gcc --sysroot=$QNX_TARGET"export PKG_CONFIG_PATH PKG_CONFIG_SYSROOT_DIR CC
  • 1
  • 2
  • 3
  • 4
  • 5

保存之后:

$source qnx660-env.sh
  • 1
  • 2

2. configure 
进入glib目录,执行:

./configure --prefix=/usr --host=arm-unknown-nto-qnx6.6.0eabi
  • 1
  • 2

3. 修正错误 
3.1 checking for libintl.h… no 
下载gettext,编译安装后解决 
3.2 configure: error: cannot run test program while cross compiling 
有几个问题会导致这个错误,原因是arm-gcc编译出来的程序无法在主机上运行,解决方法是加上configure时,加上cache文件,关闭这个验证过程:

$vim qnx.cacheglib_cv_stack_grows=noglib_cv_uscore=noac_cv_func_posix_getpwuid_r=noac_cv_func_posix_getgrgid_r=no
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

configure加入参数–cache-file=qnx.cache 
3.3 checking for res_query… configure: error: not found 
res_query在QNX系统中,是在socket库中实现的,这个要修改configure脚本 
到此configure基本上就能通过了,如果提示缺msgfmt,需要在host上安装gettext,交叉编译出搂msgfmt无法运行。 
接下来就是编译了。 
4. 编译 
4.1 pthread.h:41:2: error: #error POSIX Threads needs P1003.1b-1993 or later 
在configure时,加上CFLAGS=”-D_QNX_SOURCE” 
4.2 gclosure.c:27:17: fatal error: ffi.h: No such file or directory 
gobject的跨语言封装使用了ffi,下载libffi,编译安装 
4.3 gunixmounts.c:718:2: error: #error No _g_get_unix_mounts() implementation for system 
glib未实现qnx的_g_get_unix_mounts(),先写个空函数,其它的类同。 
至此应该能编译过了,执行:

make install DESTDIR=$QNX_TARGET
  • 1
  • 2

5.测试程序

#include <stdio.h>#include <stdlib.h>#include <glib.h>/* * ===  FUNCTION  ====================================================================== *         Name:  callback *  Description: * ===================================================================================== */static gboolean callback( gpointer user_data ){    g_message( "Hello, glib world" );    sleep( 1 );    return G_SOURCE_CONTINUE;}       /* -----  end of static function callback  ----- *//* * ===  FUNCTION  ====================================================================== *         Name:  main *  Description: * ===================================================================================== */int main ( int argc, char *argv[] ){    GMainLoop * _mainloop   =   g_main_loop_new( NULL, FALSE );    g_idle_add( callback, NULL );    g_main_loop_run( _mainloop );    g_main_loop_unref( _mainloop );    return 0;}               /* ----------  end of function main  ---------- */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

编译:

$CC test.c `pkg-config --cflags --libs glib-2.0`
  • 1
  • 2

运行:

/a.out

阅读全文
0 0
原创粉丝点击