glib源码安装使用方法
glib库是GTK+和GNOME工程的基础底层核心程序库,是一个综合用途的实用的轻量级的C程序库,它提供C语言的常用的数据结构的定义、相关的处理函数,有趣而实用的宏,可移植的封装和一些运行时机能,如事件循环、线程、动态调用、对象系统等的API。它能够在类UNIX的操作系统平台(如LINUX、HP-UNIX等)、WINDOWS、OS2和BeOS等操作系统台上运行。
本文将介绍在linux下源码安装glib库的过程,这过程很麻烦,一点都不轻松,故记录下。
------
1、安装glib
http://ftp.acc.umu.se/pub/GNOME/sources/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是提供数据压缩用的函式库。
http://www.zlib.net/ (下载地址在网页的中间部分)
我下载了个zlib-1.2.8.tar.gz,解压、进目录,三部曲:
./configure
make
make install
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
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配置文件路径找到相应的头文件路径和库文件路径。
https://www.freedesktop.org/wiki/Software/pkg-config/
我下载了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语言中使用正则表达式的问题。
https://sourceforge.net/projects/pcre/files/pcre/
我下载了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-.
所以第一步是为了解决Unicode、UTF-8的支持,仅限于pcre7.9以上版本
*安装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.: cannot open shared object file: No such file or directory pcretest: error while loading shared libraries: libpcreposix.so.: cannot open shared object file: No such file or directory
这种情况好像大多数linux都会发生,只需要自己建立一个软链接即可:
ln -s /usr/local/lib/libpcre.so. /lib ln -s /usr/local/lib/libpcreposix.so. /lib
(如果之后还没用,可以考虑把/lib换/lib64)
6、glib使用方法
*如果都按照上面所列举的种种问题仔细折腾了后还有问题的话,请留言给我。(本人在Kali2、Kali Rolling、Ubuntu等都测试过了)
现在写一个简单的c语言代码,命名为hello.c
#include <glib.h>
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 ;
}
编译如下:
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)
glib源码安装使用方法的更多相关文章
- 源码安装nginx 方法二
yum 仓库不能用大写字母 [root@oldboy conf.d]# gzip * 压缩当前目录下的所有文件 gzip ./* gzip . gzip./ # 关闭防火墙和selinux [root ...
- Mininet系列实验(一):Mininet使用源码安装
1 实验目的 掌握Mininet使用源码安装的方法. 2 实验原理 Mininet 是一个轻量级软件定义网络和测试平台:它采用轻量级的虚拟化技术使一个单一的系统看起来像一个完整的网络运行相关的内核系统 ...
- mono-3.4.0 源码安装时出现的问题 [do-install] Error 2 [install-pcl-targets] Error 1 解决方法
Mono 3.4修复了很多bug,继续加强稳定性和性能(其实Mono 3.2.8 已经很稳定,性能也很好了),但是从http://download.mono-project.com/sources/m ...
- 织梦dedecms源码安装方法
织梦dedecms源码安装方法 第一步: 上传所有文件到空间 注意:(由于有很多人反应安装后首页样式都乱的,所以强烈要求安装到根目录,如:127.0.0.1 / www.xxx.com,或者二级域名也 ...
- 记录一个源码安装mysql5.6的方法
https://www.jb51.net/article/118853.htm 如果之前源码安装过mysql5.6的话,卸载方法如下:rm -rf /var/lib/mysql/rm -rf /usr ...
- Django源码安装方法及创建启动项目
一.源码安装方法 下载源码包:https://www.djangoproject.com/download/ 输入以下命令并安装: tar xzvf Django-X.Y.tar.gz # 解压下载包 ...
- nginx源码安装方法
nginx源码安装方法 安装方法如下 1.安装nginx必要的源码依赖软件包. yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zli ...
- linux源码安装软件的一般方法
rhel系统貌似安装不了xmgrace,配置的时候居然说要那个M*tif库.百度了一下,需要openmotif库,然后用root账户想要用yum安装一下这个库,搞了好久没搞懂.后面搞明白了,原因竟是因 ...
- 国产龙芯服务器源码安装PostgreSQL数据库的方法
1. 公司最近有一些国产化项目的需求, 要求在国产CPU的服务器上面安装pg数据库等. 2.. 但是差查了下中标麒麟的官网,在龙芯MIPS的操作系统包源里面仅有 postgreSQL 9.2 版本的r ...
随机推荐
- PHP程序效率优化
1.在可以用file_get_contents替代file.fopen.feof.fgets等系列方法的情况下,尽量用 file_get_contents,因为他的效率高得多!但是要注意file_ge ...
- SQL游标+递归查询客户子客户转换率
ALTER PROCEDURE [dbo].[Account3YearsConversion ] as DECLARE @AccountId UNIQUEIDENTIFIER , @yearbefor ...
- Maven命令行创建web项目,并部署到jobss当中(解决No plugin found for prefix 'jboss-as' in the current project and in the plugin groups [org.apache.maven.plugins,问题)
首件创建项目:此处可参照:http://maven.apache.org/guides/mini/guide-webapp.html mvn archetype:generate -DgroupId= ...
- api (二) 创建控件 (转)
在Win32 SDK环境下,怎么来创建常用的那些基本控件呢?我们知道如果用MFC,简单的拖放即可完成大多数控件的创建,但是我们既然是用Windows SDK API编程,当然是从根上解决这个问题,实际 ...
- windows如何获取Win10 Win8 Win8.1版本
GetVersionEx 在win8 win8.1 win10 之后已经无法使用,如果非要使用的话需要让exe嵌入manifest,mainfest如下.这个文件需要已utf-8存储. <?xm ...
- Matlab基础知识
一.常用命令:普通的如cd.ls和linux下一样 clc:清除工作窗口中的所有显示内容 clf:清除图形窗口 whos:列出当前工作空间中所有变量,以及它们的名字.尺寸(比如一个矩阵或数组的行列维数 ...
- JAVA注释方式--目前用的
代码整洁,规范,可读,注释是关键之一. 1.整个类文件注释 注释结构:/* * @(#){类名称}.java {创建时间} * * {某人或某公司具有完全的版权} * {使用者必须经过许可 ...
- js-计算器
<div class="main"><h1>HTML5-计算器</h1> <input id="num1& ...
- Java引用数据类型
值传递:方法调用时,实际参数把它的值传递给对应的形式参数,方法执行中形式参数值的改变不影响实际参 数的值.引用传递:也称为传地址.方法调用时,实际参数的引用(地址,而不是参数的值)被传递给方法中相对应 ...
- Python核心编程笔记--随机数
#第一步引入模块 import random #第二步生成随机数 print random.randint(1,3);#[1,2,3]注意这里是闭区间.