GLib source code Installation use method

Source: Internet
Author: User
Tags ffi

The glib library is the foundation underlying core library for GTK + and GNOME Engineering and is a versatile and practical lightweight C library that provides definitions of commonly used data structures in C, related processing functions, interesting and useful macros, portable encapsulation, and some runtime functions such as event loops, threads, APIs for dynamic invocation, object systems, and so on. It can be run on Unix-like operating system platforms (such as Linux, Hp-unix, etc.), WINDOWS, OS2, and BeOS.

This article will introduce in Linux under the source code installation glib library process, this process is very troublesome, not easy at all, so record.

------

1, installation glib

http://ftp.acc.umu.se/pub/GNOME/sources/glib/

I downloaded a glib-2.48.1.tar.xz, if the. tar.xz format is extracted with TAR-XVF, if it is. tar.gz format with TAR-ZXVF decompression

After extracting into the catalogue, the trilogy:

./Configuremake makeinstall

It looks simple, but the first step./configure problems, many problems please see the following various solutions.

2, zlib problem

The error is as follows:

Configure:error: * * * working zlib Library and headers not found * * *

Zlib,zlib is a library of functions that provides data compression, starting from glib-2.23.

http://www.zlib.net/(in the middle part of the Web page)

I downloaded a zlib-1.2.8.tar.gz, extracted, into the catalogue, trilogy:

./Configuremake makeinstall

3, Libffi problem

The error is as follows:

' Libffi '   ifin a non-pkg-config pkg-config   man for more details.

The full name of the "FFI" is foreign Function Interface, which usually refers to code that allows code written in one language to call another language. The Libffi library only provides the lowest-level, schema-dependent, complete "FFI", which must be a layer on which to manage the format conversion of the parameters between the two languages.

http://sourceware.org/libffi/

I downloaded the libffi-3.2.1.tar.gz, unzip, into the catalogue, trilogy:

./Configuremake makeinstall

4, Pkg-config problem

The error is as follows:

pkg-config script could not being found or is too old.  inch pkg-config.

Pkg-config can find the corresponding header file path and library file path according to the software's. PC Profile path during software installation.

https://www.freedesktop.org/wiki/Software/pkg-config/

I downloaded the pkg-config-0.29.1.tar.gz, unzip, into the catalogue, trilogy:

./Configuremake makeinstall

If the first step encounters the following error:

Pkg-config " glib-2.0 >= 2.16 " could not being found. Please set glib_cflags and glib_libs to the correct values or pass--with-internal-glib to configure-use the bundled CO Py.

Just need:

./configure--with-internal-glib

5, Pcre problem

The error is as follows:

 configure:error:Package requirements (libpcre >= 8.13  ) were not Met:no package   " libpcre   "  Foundconsider adjusting the Pkg_config _path environment variable  if   youinstalled software  in  a Non-standard Prefix. Alternatively, you could set the environment variables Pcre_cflagsand pcre_libs to avoid the need-call  pkg-config  . See the  pkg-config  man  page for  more  details. 

PCRE (perl Compatible Regular Expressions) is a Perl library that includes a Perl-compatible regular expression library. These are useful for using the same syntax and semantics as Perl 5 when performing regular expression pattern matching, and can also be used to solve problems with regular expressions in C.

Https://sourceforge.net/projects/pcre/files/pcre/

I downloaded the pcre-8.38.tar.gz, unzip, into the catalogue, and changed the trilogy:

./configure--enable-utf8--enable-unicode-Propertiesmake makeinstall

If the first step is just./configure, then install glib will continue to error:

 for inch  * * * The system-supplied PCRE does not support Unicode properties or utf-8.

So the first step is to resolve Unicode, UTF-8 support, limited to pcre7.9 or later

* Install Pcre If the error is as follows:

 for C + + Support

That's what you're using. Linux does not support C + + compilation, only requires:

Install build-essential

* * When the pcre is installed, enter PCRETEST-C to print the installation of Pcre, the general output is as follows:

PCRE version 8.38 2015-11-23compiled 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 =  parentheses nest limit = $  default match limit = 10000000  default Recursio N depth limit = 10000000  Match recursion uses stack

And if the error is:

 while loading shared libraries:libpcre.so. 1 Object file file   while loading shared libraries:libpcreposix.so. 0 Object file file or directory

It seems like most Linux will happen, just create a soft link yourself:

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

(If it doesn't work, consider changing the/lib to/lib64)

6. How to use glib

* If you have to follow the above listed questions carefully toss after the problem, please leave a message to me. (I have tested it in Kali2, Kali rolling, Ubuntu, etc.)

Now write a simple C-language code named HELLO.C

#include <glib.h>intMainintargcChar**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;}

Compile as follows:

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

If the error is reported in some Linux:

Undefined reference to ' g_list_append'undefined reference to ' G_list_first'

That's because some GCC has an order problem with the compilation parameters, $ (pkg-config--cflags--libs glib-2.0) is placed in front of the source file, and when the compiler encounters a function that cannot be resolved in the source file, look for the relevant information in the options after the source file, Then there is a compilation error, which means that the associated function definition cannot be found.

So just need:

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

GLib source code Installation use method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.