Chinaunix首页 | 论坛 | 博客
  • 博客访问: 24656
  • 博文数量: 9
  • 博客积分: 45
  • 博客等级: 民兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-20 03:13
个人简介

我可以用几条微不足道的标签来定义:“石油炼化产业工人”、“程序匠人”、“成人大学学历”、“一个还算顾家的男人”、“会弹吉他和画画的父亲”、“他”。没错,你没看错,“他”也是我的标签,在熙熙攘攘的人群中,我就是那个“他”,默默无闻却自得其乐的耕耘在自己的一方天地里!

我的朋友

分类: C/C++

2015-04-11 02:56:41


botbrew下写glib2程序



作者

He YiJun – storysnailgmail.com

团队

ls

版权

转载请保留本声明!


本文档包含的原创代码根据General Public License,v3 发布
GPLv3
许可证的副本可以在这里获得:

本文档根据GNU Free Documentation License 1.3发布
GFDL1.3
许可证的副本可以在这里获得:

文中所引用的软件版权详见各软件版权具体声明,中所提及的所有商标均为各自商标所有人的财产。
作者在此向所有提供过帮助和支持的朋友表示感谢,此致!

更新

2014-11-10

修改版权

...

...





前言:

...

一:配置botbrew中的glib2函数库

1:
启动botbrew后,在其主界面选择安装libglib2.0libglib2.0-binlibglib2.0-devlibglib2.0-doc


2:
安装好所需软件后,将下面的内容保存成glibconfig.h文件,进入终端模拟器,输入su,取得root权限,然后输入

 cp glibconfig.h /botbrew/include/glib-2.0/   


点击(此处)折叠或打开

  1. /**************************************************************************************************
  2. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
  3.                                glibconfig.h
  4.                     This file just for botbrew's glib2.
  5.     Develop Team : ls
  6.     Main Programmer : He YiJun (storysnail<at>gmail.com)
  7.     License : GPL2
  8.     Last Update : 2013-06-15
  9. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
  10. **************************************************************************************************/
  11. #ifndef __G_LIBCONFIG_H__
  12. #define __G_LIBCONFIG_H__

  13. #include <glib/gmacros.h>
  14. #include <limits.h>
  15. #include <float.h>
  16. #define GLIB_HAVE_ALLOCA_H
  17. #define GLIB_HAVE_SYS_POLL_H

  18. /* Specifies that GLib's g_print*() functions wrap the
  19.  * system printf functions. This is useful to know, for example,
  20.  * when using glibc's register_printf_function().
  21.  */
  22. #define GLIB_USING_SYSTEM_PRINTF

  23. G_BEGIN_DECLS

  24. #define G_MINFLOAT FLT_MIN
  25. #define G_MAXFLOAT FLT_MAX
  26. #define G_MINDOUBLE DBL_MIN
  27. #define G_MAXDOUBLE DBL_MAX
  28. #define G_MINSHORT SHRT_MIN
  29. #define G_MAXSHORT SHRT_MAX
  30. #define G_MAXUSHORT USHRT_MAX
  31. #define G_MININT INT_MIN
  32. #define G_MAXINT INT_MAX
  33. #define G_MAXUINT UINT_MAX
  34. #define G_MINLONG LONG_MIN
  35. #define G_MAXLONG LONG_MAX
  36. #define G_MAXULONG ULONG_MAX

  37. typedef signed char gint8;
  38. typedef unsigned char guint8;
  39. typedef signed short gint16;
  40. typedef unsigned short guint16;
  41. #define G_GINT16_MODIFIER "h"
  42. #define G_GINT16_FORMAT "hi"
  43. #define G_GUINT16_FORMAT "hu"
  44. typedef signed int gint32;
  45. typedef unsigned int guint32;
  46. #define G_GINT32_MODIFIER ""
  47. #define G_GINT32_FORMAT "i"
  48. #define G_GUINT32_FORMAT "u"
  49. #define G_HAVE_GINT64 1 /*deprecated, always true */

  50. G_GNUC_EXTENSION typedef signed long long gint64;
  51. G_GNUC_EXTENSION typedef unsigned long long guint64;

  52. #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL))
  53. #define G_GUINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##ULL))
  54. #define G_GINT64_MODIFIER "ll"
  55. #define G_GINT64_FORMAT "lli"
  56. #define G_GUINT64_FORMAT "llu"

  57. #define GLIB_SIZEOF_VOID_P 4
  58. #define GLIB_SIZEOF_LONG 4
  59. #define GLIB_SIZEOF_SIZE_T 4

  60. typedef signed int gssize;
  61. typedef unsigned int gsize;
  62. #define G_GSIZE_MODIFIER ""
  63. #define G_GSSIZE_FORMAT "i"
  64. #define G_GSIZE_FORMAT "u"

  65. #define G_MAXSIZE G_MAXUINT
  66. #define G_MINSSIZE G_MININT
  67. #define G_MAXSSIZE G_MAXINT

  68. typedef gint64 goffset;
  69. #define G_MINOFFSET G_MININT64
  70. #define G_MAXOFFSET G_MAXINT64

  71. #define G_GOFFSET_MODIFIER G_GINT64_MODIFIER
  72. #define G_GOFFSET_FORMAT G_GINT64_FORMAT
  73. #define G_GOFFSET_CONSTANT(val) G_GINT64_CONSTANT(val)

  74. #define GPOINTER_TO_INT(p) ((gint) (p))
  75. #define GPOINTER_TO_UINT(p) ((guint) (p))

  76. #define GINT_TO_POINTER(i) ((gpointer) (i))
  77. #define GUINT_TO_POINTER(u) ((gpointer) (u))

  78. typedef signed int gintptr;
  79. typedef unsigned int guintptr;

  80. #define G_GINTPTR_MODIFIER ""
  81. #define G_GINTPTR_FORMAT "i"
  82. #define G_GUINTPTR_FORMAT "u"

  83. #ifdef NeXT /*@#%@! NeXTStep */
  84. # define g_ATEXIT(proc) (!atexit (proc))
  85. #else
  86. # define g_ATEXIT(proc) (atexit (proc))
  87. #endif

  88. #define g_memmove(dest,src,len) G_STMT_START { memmove ((dest), (src), (len)); } G_STMT_END

  89. #define GLIB_MAJOR_VERSION 2
  90. #define GLIB_MINOR_VERSION 24
  91. #define GLIB_MICRO_VERSION 2

  92. #define G_OS_UNIX

  93. #define G_VA_COPY va_copy

  94. #ifdef __cplusplus
  95. #define G_HAVE_INLINE 1
  96. #else /*!__cplusplus */
  97. #define G_HAVE_INLINE 1
  98. #define G_HAVE___INLINE 1
  99. #define G_HAVE___INLINE__ 1
  100. #endif /*!__cplusplus */

  101. #ifdef __cplusplus
  102. #define G_CAN_INLINE 1
  103. #else /*!__cplusplus */
  104. #define G_CAN_INLINE 1
  105. #endif

  106. #ifndef __cplusplus
  107. # define G_HAVE_ISO_VARARGS 1
  108. #endif
  109. #ifdef __cplusplus
  110. # define G_HAVE_ISO_VARARGS 1
  111. #endif

  112. /* gcc-2.95.x supports both gnu style and ISO varargs, but if -ansi
  113.  * is passed ISO vararg support is turned off, and there is no work
  114.  * around to turn it on, so we unconditionally turn it off.
  115.  */
  116. #if __GNUC__ == 2 && __GNUC_MINOR__ == 95
  117. # undef G_HAVE_ISO_VARARGS
  118. #endif

  119. #define G_HAVE_GNUC_VARARGS 1
  120. #define G_HAVE_GROWING_STACK 0

  121. #define G_HAVE_GNUC_VISIBILITY 1
  122. #if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
  123. #define G_GNUC_INTERNAL __attribute__((visibility("hidden")))
  124. #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
  125. #define G_GNUC_INTERNAL __hidden
  126. #elif defined (__GNUC__) && defined (G_HAVE_GNUC_VISIBILITY)
  127. #define G_GNUC_INTERNAL __attribute__((visibility("hidden")))
  128. #else
  129. #define G_GNUC_INTERNAL
  130. #endif

  131. #define G_THREADS_ENABLED
  132. #define G_THREADS_IMPL_POSIX
  133. typedef struct _GStaticMutex GStaticMutex;
  134. struct _GStaticMutex
  135. {
  136.   struct _GMutex *runtime_mutex;
  137.   union {
  138.     char pad[24];
  139.     double dummy_double;
  140.     void *dummy_pointer;
  141.     long dummy_long;
  142.   } static_mutex;
  143. };
  144. #define G_STATIC_MUTEX_INIT { NULL, { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} } }
  145. #define g_static_mutex_get_mutex(mutex) \
  146.   (g_thread_use_default_impl ? ((GMutex*)(gpointer) ((mutex)->static_mutex.pad)) : \
  147.    g_static_mutex_get_mutex_impl_shortcut (&((mutex)->runtime_mutex)))
  148. /* This represents a system thread as used by the implementation. An
  149.  * alien implementaion, as loaded by g_thread_init can only count on
  150.  * "sizeof (gpointer)" bytes to store their info. We however need more
  151.  * for some of our native implementations. */
  152. typedef union _GSystemThread GSystemThread;
  153. union _GSystemThread
  154. {
  155.   char data[4];
  156.   double dummy_double;
  157.   void *dummy_pointer;
  158.   long dummy_long;
  159. };

  160. #define G_ATOMIC_OP_MEMORY_BARRIER_NEEDED 1

  161. #define GINT16_TO_LE(val) ((gint16) (val))
  162. #define GUINT16_TO_LE(val) ((guint16) (val))
  163. #define GINT16_TO_BE(val) ((gint16) GUINT16_SWAP_LE_BE (val))
  164. #define GUINT16_TO_BE(val) (GUINT16_SWAP_LE_BE (val))
  165. #define GINT32_TO_LE(val) ((gint32) (val))
  166. #define GUINT32_TO_LE(val) ((guint32) (val))
  167. #define GINT32_TO_BE(val) ((gint32) GUINT32_SWAP_LE_BE (val))
  168. #define GUINT32_TO_BE(val) (GUINT32_SWAP_LE_BE (val))
  169. #define GINT64_TO_LE(val) ((gint64) (val))
  170. #define GUINT64_TO_LE(val) ((guint64) (val))
  171. #define GINT64_TO_BE(val) ((gint64) GUINT64_SWAP_LE_BE (val))
  172. #define GUINT64_TO_BE(val) (GUINT64_SWAP_LE_BE (val))
  173. #define GLONG_TO_LE(val) ((glong) GINT32_TO_LE (val))
  174. #define GULONG_TO_LE(val) ((gulong) GUINT32_TO_LE (val))
  175. #define GLONG_TO_BE(val) ((glong) GINT32_TO_BE (val))
  176. #define GULONG_TO_BE(val) ((gulong) GUINT32_TO_BE (val))
  177. #define GINT_TO_LE(val) ((gint) GINT32_TO_LE (val))
  178. #define GUINT_TO_LE(val) ((guint) GUINT32_TO_LE (val))
  179. #define GINT_TO_BE(val) ((gint) GINT32_TO_BE (val))
  180. #define GUINT_TO_BE(val) ((guint) GUINT32_TO_BE (val))
  181. #define GSIZE_TO_LE(val) ((gsize) GUINT32_TO_LE (val))
  182. #define GSSIZE_TO_LE(val) ((gssize) GINT32_TO_LE (val))
  183. #define GSIZE_TO_BE(val) ((gsize) GUINT32_TO_BE (val))
  184. #define GSSIZE_TO_BE(val) ((gssize) GINT32_TO_BE (val))
  185. #define G_BYTE_ORDER G_LITTLE_ENDIAN

  186. #define GLIB_SYSDEF_POLLIN =1
  187. #define GLIB_SYSDEF_POLLOUT =4
  188. #define GLIB_SYSDEF_POLLPRI =2
  189. #define GLIB_SYSDEF_POLLHUP =16
  190. #define GLIB_SYSDEF_POLLERR =8
  191. #define GLIB_SYSDEF_POLLNVAL =32

  192. #define G_MODULE_SUFFIX "so"

  193. /* A GPid is an abstraction for a process "handle". It is *not* an
  194.  * abstraction for a process identifier in general. GPid is used in
  195.  * GLib only for descendant processes spawned with the g_spawn*
  196.  * functions. On POSIX there is no "process handle" concept as such,
  197.  * but on Windows a GPid is a handle to a process, a kind of pointer,
  198.  * not a process identifier.
  199.  */
  200. typedef int GPid;

  201. #define GLIB_SYSDEF_AF_UNIX 1
  202. #define GLIB_SYSDEF_AF_INET 2
  203. #define GLIB_SYSDEF_AF_INET6 10

  204. #define GLIB_SYSDEF_MSG_OOB 1
  205. #define GLIB_SYSDEF_MSG_PEEK 2
  206. #define GLIB_SYSDEF_MSG_DONTROUTE 4

  207. G_END_DECLS

  208. #endif /*GLIBCONFIG_H */


二 编译运行glib2程序

关于glib2的程序在互联网上有很多,有一些显然已经过时了,但我在botbrew中编译时也依然可以通过,只是多了些该函数库已经过时的警告,下面给出一个简单的程序和makefile实例,搞程序的人还是用代码说话更直接。


点击(此处)折叠或打开

  1. /**************************************************************************************************
  2. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
  3.                                gtest.c

  4.     Develop Team : ls
  5.     Main Programmer : He YiJun (storysnail<at>gmail.com)
  6.     License : GPLv3
  7.     Last Update : 2013-03-03
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
  9. **************************************************************************************************/
  10. #include <glib.h>
  11. int main(int argc, char *argv[])
  12. {
  13.   GRand *rand; GTimer *timer;
  14.   gint n;
  15.   gint i, j;
  16.   gulong x = 0;
  17.   //创建随机数对象后产生随机数并显示出来,之后释放随机数对象
  18.   rand = g_rand_new();
  19.   for(n=0; n<20; n++) {
  20.     g_print("%d\t",g_rand_int_range(rand,1,100));
  21.   }
  22.   g_rand_free(rand);
  23.   g_print("\n");
  24.   //创建计时器,之后让机器忙等待,然后输出计时结果
  25.   timer = g_timer_new();
  26.   g_timer_start(timer);

  27.   for(i=0; i<10000; i++)
  28.     for(j=0; j<3650; j++)
  29.       x++;
  30.   g_timer_stop(timer);

  31.   g_print("%ld\tall:%.2f seconds was used!\n",x,g_timer_elapsed(timer,NULL));
  32.   return 0;
  33. }



  34. #**************************************************************************************************
  35. #* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
  36. #
  37. # Develop Team : ls
  38. # Programmer : He YiJun (storysnail<at>gmail.com )
  39. # Comments : Ling Ying
  40. # License : GPLv3
  41. # Last Update : 2013-02-14
  42. #* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
  43. #*************************************************************************************************/
  44. all:gtest
  45. CC=gcc
  46. CFLAGS = -Wall -ggdb

  47. OBJFILES = gtest.o

  48. gtest:$(OBJFILES)
  49.     $(CC) $(CFLAGS) -I/botbrew/include/glib-2.0-L/botbrew/lib -lm -lglib-2.0$(OBJFILES)-o gtest

  50. gtest.o:gtest.c
  51.     $(CC)$(CFLAGS)-I/botbrew/include/glib-2.0-L/botbrew/lib -lm -lglib-2.0-c gtest.c -o gtest.o

  52. clean:
  53.     rm -f *.o *~ gtest


最后是一张程序运行的截图




阅读(1192) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~