glib 2.0 arm linux,glib源码安装使用方法

news/2024/7/5 4:43:04

glib库是GTK+和GNOME工程的基础底层核心程序库,是一个综合用途的实用的轻量级的C程序库,它提供C语言的常用的数据结构的定义、相关的处理函数,有趣而实用的宏,可移植的封装和一些运行时机能,如事件循环、线程、动态调用、对象系统等的API。它能够在类UNIX的操作系统平台(如LINUX、HP-UNIX等)、WINDOWS、OS2和BeOS等操作系统台上运行。

本文将介绍在linux下源码安装glib库的过程,这过程很麻烦,一点都不轻松,故记录下。

------

1、安装glib

我下载了个glib-2.48.1.tar.xz,如果是.tar.xz格式用tar -xvf解压,如果是.tar.gz格式用tar -zxvf解压

解压后进入目录后,三部曲:

./configure make make install

看起来是简单,但第一步./configure问题多多,诸多问题请看下面各种解决法子。

2、zlib问题

报错如下:

configure: error: *** Working zlib library and headers not found ***

自glib-2.23开始就需要zlib,zlib是提供数据压缩用的函式库。

(下载地址在网页的中间部分)

我下载了个zlib-1.2.8.tar.gz,解压、进目录,三部曲:

./configure make make install

apt-get install zlib1g-dev

3、libffi问题

报错如下:

No package 'libffi' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables LIBFFI_CFLAGS and LIBFFI_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.

"FFI" 的全名是Foreign Function Interface,通常指的是允许以一种语言编写的代码调用另一种语言的代码。而libffi库只提供了最底层的、与架构相关的、完整的"FFI",在它之上必须有一层来负责管理两种语言之间参数的格式转换。

我下载了libffi-3.2.1.tar.gz,解压、进目录,三部曲:

./configure make make install

apt-get install libffi-dev

4、pkg-config问题

报错如下:

configure: error: The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config.

pkg-config能根据软件安装时软件的.pc配置文件路径找到相应的头文件路径和库文件路径。

我下载了pkg-config-0.29.1.tar.gz,解压、进目录,三部曲:

./configure make make install

如果第一步遇到如下错误:

configure: error: Either a previously installed pkg-config or "glib-2.0 >= 2.16" could not be found. Please set GLIB_CFLAGS and GLIB_LIBS to the correct values or pass --with-internal-glib to configure to use the bundled copy.

只需要:

./configure --with-internal-glib

5、pcre问题

报错如下:

configure: error: Package requirements (libpcre >= 8.13) were not met: No package 'libpcre' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables PCRE_CFLAGS and PCRE_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.

PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括perl兼容的正则表达式库。这些在执行正规表达式模式匹配时用与Perl 5同样的语法和语义是很有用的,也可以来解决C语言中使用正则表达式的问题。

我下载了pcre-8.38.tar.gz,解压、进目录,改动的三部曲:

./configure --enable-utf8 --enable-unicode-properties make make install

如果第一步只是./configure,到时候安装glib会继续报错:

checking for Unicode support in PCRE... no configure: error: *** The system-supplied PCRE does not support Unicode properties or UTF-8.

所以第一步是为了解决Unicode、UTF-8的支持,仅限于pcre7.9以上版本

sudo apt-get install libglib2.0-dev

*安装pcre如果报错如下:

configure: error: You need a C++ compiler for C++ support

那是你所用的linux没支持c++编译,只需要:

apt-get install build-essential

**当安装好pcre后,输入pcretest -C来打印pcre的安装情况,一般输出如下:

PCRE version 8.38 2015-11-23 Compiled with 8-bit support UTF-8 support Unicode properties support No just-in-time compiler support Newline sequence is LF \R matches all Unicode newlines Internal link size = 2 POSIX malloc threshold = 10 Parentheses nest limit = 250 Default match limit = 10000000 Default recursion depth limit = 10000000 Match recursion uses stack

而如果报错为:

pcretest: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory pcretest: error while loading shared libraries: libpcreposix.so.0: cannot open shared object file: No such file or directory

这种情况好像大多数linux都会发生,只需要自己建立一个软链接即可:

ln -s /usr/local/lib/libpcre.so.1 /lib ln -s /usr/local/lib/libpcreposix.so.0 /lib

(如果之后还没用,可以考虑把/lib换/lib64)

6、glib使用方法

*如果都按照上面所列举的种种问题仔细折腾了后还有问题的话,请留言给我。(本人在Kali2、Kali Rolling、Ubuntu等都测试过了)

现在写一个简单的c语言代码,命名为hello.c

#include int main(int argc, char** argv){ GList* list=NULL; list=g_list_append(list,"Hello world!"); list=g_list_append(list,"made by pcat"); list=g_list_append(list,"http://pcat.cnblogs.com"); printf("The first item is %s\n",g_list_first(list)->data); return 0; }

编译如下:

gcc $(pkg-config --cflags --libs glib-2.0) hello.c -o hello ./hello

如果在一些linux上报错:

undefined reference to `g_list_append' undefined reference to `g_list_first'

那是因为有些gcc存在编译参数的顺序问题,$(pkg-config --cflags --libs glib-2.0)放在源文件的前面,而当编译器在源文件中遇到不能解析的函数时,在源文件之后的选项中寻找相关的信息,那么就出现了编译错误,也就是无法找到相关的函数定义。

所以只需要:

gcc hello.c -o hello $(pkg-config --cflags --libs glib-2.0)

1.查看安装的所有软件

dpkg -l

例如:dpkg -l | grep ftp

2.查看软件安装的路径

dpkg -L | grep ftp

也可以用 whereis ftp

3.查看软件版本

aptitude show

例如:aptitude  show ftp

移植glib到arm

error: cannot run test program while cross compiling

./configure --host=arm-linux --cache-file=arm-linux.cache

OK这样就搞定了


http://lihuaxi.xjx100.cn/news/239133.html

相关文章

解除微信回调的Activity必须在包名.wxapi下的限制

很久以前写过一篇文章:Android打包之多版本、多环境、多渠道。里面主要提到了将测试环境和正式环境的包分成不同的包名,同时安装在手机上,以便我们调试。同时,通过manifest的占位符,动态替换icon和label,让…

二次开发photoshop_Photoshop 101:Web开发人员简介

二次开发photoshop介绍 (Introduction) Often, when working as web developer, we need to integrate templates. They can be from Photoshop or other software. In this article, we will have a look at the basics of Photoshop for web developers.通常,在作…

基于web创建逼真的3D图形 | CSS技巧

在成为一名web开发者之前,我从事于视觉设计行业,创造屡获殊荣,电影和电视节目等高端3D效果,例如 Tron, The Thing, Resident Evil,和 Vikings 。为了能够创造这些效果,我们需要使用高度复杂的动画软件,例如…

linux error log 换行,日志提示

日志提示线上问题,需要看日志。控制台可以打印Mybatis操作的SQL语句。开发流程:第一步:加入依赖image.png第二步:在项目的resources中加入log4j属性文件image.png第三步:演示image.png扩展了解一、日志概念的介绍Log4j…

快速 开发平台 架构_快速介绍清洁架构

快速 开发平台 架构by Daniel Deutsch由Daniel Deutsch 快速介绍清洁架构 (A quick introduction to clean architecture) In an open source project I started to contribute to, the concept of “clean architecture” was brought to me.在一个我开始参与的开源项目中 &a…

安装Python的wx库

2019独角兽企业重金招聘Python工程师标准>>> 遇到问题1:pip不是内部或外部命令,也不是可运行的程序 解决办法:修改环境变量:变量值改为:C:\Python27\;C:\Python27\Scripts; 遇到问题2:wxPython.…

Solaris下ftp配置(初稿-待补充)

1.自带ftp版本 Version wu-2.6.2 2.ftp启动与停止 启动并启用ftp: svcadm enable network/ftp 停止并禁用ftp: svcadm disable network/ftp 3.使某个系统用户无法使用ftp或者恢复使用ftp vi /etc/ftpd/ftpusers 向其中添加要禁止使用ftp的…

c语言程序学生成绩系统论文,c语言程序设计-学生成绩管理系统论文.doc

c语言程序设计-学生成绩管理系统论文C语言程序设计课程设计报告- PAGE 11 -中南民族大学工商学院电子信息与计算机技术系项目名称: 学生成绩管理系统学生姓名:学 号:班 级:指导教师:20年月日学生成绩管理系统目录TOC \…