Ubuntu Complete Installation GLib experience

Source: Internet
Author: User
Tags unsupported

after learning the data structure, feel to the storage of a new understanding, on the basis of dynamic memory, the chain list has the absolute flexibility, can give the unknown length of data processing to bring convenience, but in the process of writing code constantly, feel the deep hatred, every time to realize the function, almost the source code has changed, In other words, each method of using a linked list is almost different, which increases the cost of maintaining the functions of the linked list, queue, and stack, and does not know the actual difference of each version even after n days.
This is my thinking is not Linux can provide out-of-the-box list implementation, after all, in the kernel of a large number of implementation of the list of marvellous source code, will not be good-hearted encapsulation into the library for others to use it? Unfortunately, Linux did not do, so basically to use the chain list and queue all need to implement the source code, for me such a lazy cancer patients this is unbearable, I found the relevant information on the Internet, finally let me find the third-party glib library. The function of this library is very powerful, from the definition of g_uint8 type to the implementation of G_thread thread, this library can be done, the following simple introduction, the full function of the description of Baidu it.
GLib Introduction
GLib Library is the most common C language function library under the Linux platform, it has very good portability and practicability.
1 type definition
Integer type. Boolean type. Character type. Floating-point type. Pointers. Gconstpointer for the const void* of standard C
       2 GLib Macro
Common macros
 conversion between integral type and pointer type
Debug MacrosPre-condition Check,Assertion,determine if the build is a specified artifact3 Common functions 4 memory management 4 string processing
string manipulation,Modify the string,string conversions,other string conversion functions
 5 Data structures
 linked list,trees,hash table,
6 gstringGstring is similar to the standard C string type, but gstring can grow automatically, which prevents buffer overflow in the program. Here is the definition of gstring: 7. Timer function 8 error handling function9 Other Utility functions
Basically can be used on the function of this library has been implemented
OK, let's get down to the chase and compile the Hello World together.

First introduce the development environment

Pc:xp SP3, Depth perfect pure Standard Edition
Virtual machines: VMware? Workstation, Version:9.0.2 build-1031769
Ubuntu: Huaqing Vision School Edition 12.04

today's goal is to compile the programmer's Standard starter program, which is the "Hello World" that the programmer will use first, and the function is to print using the g_printf function.
The source code is as follows:

#include <stdio.h>#include "glib.h"int main (int agrc, char **argv){g_printf ("Hello world!\n");return 0;}
Today's goal is to compile and run this program.

First come up is what also no matter, first write good code, GCC again, in case of passing, this kind of thing happened already.

[Email protected]:~/16021$ gcc hello.c hello.c:3:18:fatal error:glib.h:no such file or directorycompilation terminated.
Unfortunately, the error said there is no header file Glib.h, but it is not surprising, because glib is a third-party library, if there is no installation will not have the library file.
The following target, install the third-party library file glib, first download glib source code, because apt did not find a direct installation, I downloaded the glib-2.0.6.tar.gz, the other version did not test, found that glib has a dependency libffi-3.2.1.tar.gz this library, download, find ways to get Ubuntu inside, and then tar decompression

Need to install firstlibffi-3.2.1.tar.gz Library
Unzip
[Email protected]:~/16021$ tar-xzvf libffi-3.2.1.tar.gz
Enterlibffi-3.2.1 folder for the classic trilogy./configure make makes install
I've added sudo permissions to all three steps to prevent the lack of permissions
This library is installed quickly, and then the same action is treatedglib-2.0.6.tar.gz.

Normally there should be no errors, which is basically half the success.


This is the code can be found in the/usr/local/lib and/usr/local/include folder glib2.0, this time to compile and try again.

And you said I didn't have a header file? It turns out that we used the header file with <> the header file directory is located in the environment variable settings, directory is the/usr/include directory
, well, know the reason is good to solve, normal should be added to the GLib header file path, but I am lazy, and now is not very practical makefile, decided to copy all the head files to/usr/include directory, this operation is not recommended, But it can really solve the problem.
I have not studied the method of makefile. The following is an explanation of the operation of copying files.
 
[Email protected]:~/16021$ sudo cp-r/usr/local/include/glib-2.0/*/usr/include/
Okay, now compile it. [Email protected]:~/16021$ gcc hello.c in file included from/usr/include/glib/galloca.h:30:0, from/usr/i Nclude/glib.h:30, from hello.c:3:/usr/include/glib/gtypes.h:30:24:fatal error:glibconfig.h:no such file or directorycompilation terminated. OK, finally is another mistake, can't find the Glibconfig.h file, look for it.This file is in the/usr/local/lib/glib-2.0/include directory. Okay, the usual, copy.sudo cp/usr/local/lib/glib-2.0/include/glibconfig.h/usr/include/now compile it .
[Email protected]:~/16021$ gcc hello.c/tmp/cctk6e9q.o:in function ' main ': hello.c: (. text+0x11): Undefined reference to ' g_printf ' Collect2:ld returned 1 exit status pretty, now that the file problem is gone, start to say no function found. What happened? Library functions often need to specify the library file name at compile time, to add a try gcc hello.c-o hello-lglib-2.0
 [email protected]:~/16021$ gcc hello.c-o hello-lglib-2.0/tmp/ccxsxtrk.o:in function ' main ': hello.c: (. text+0x11): Undefined reference to ' g_printf ' Collect2:ld returned 1 exit St ATUs still can not find, in class as if to say, the custom library how to add to the environment variable, there are 3 ways, of which there are 2 kinds of shutdown does not disappear. One is to add the library file to the System library directory, one is to add the. conf file to the/etc/ld.so.conf.d/directory, both of which can be used here, and I'll use the way to write the. conf file, inin the/etc/ld.so.conf.d/directory, create a new glib.conf file, write the file/usr/local/lib/, which is the glib library file directory. After saving using the sudo ldconfig command, compile now.
I began to wonder if the library is not installed, online check how to check the installation of the library, the result is the Dpkg-l|grep glib command,

Online said a library should have-data and-dev files, I found no-dev file, install below, thank goodness apt has this installation, command is, sudo apt-get install Libglib2.0-dev installation process There is a place to Y.
installation process may fail, require update software, and then is a variety of updates can not, because the celestial LAN resources are limited, so can only think of his solution, I found my
/etc/apt/sources.list files can be updated normally, it is estimated that there is a problem with the mirror address inside. Here is a list of file contents
######################################################################################################

# deb Cdrom:[ubuntu 12.04.1 LTS _precise pangolin_-Release i386 (20120817.1)]/precise main restricted
# See Http://help.ubuntu.com/community/UpgradeNotes upgrade to# Newer versions of the Distribution.deb http://c N.archive.ubuntu.com/ubuntu/precise Main RESTRICTEDDEB-SRC http://cn.archive.ubuntu.com/ubuntu/precise main Restricted
# # Major bug fix updates produced after the final release of the## Distribution.deb http://cn.archive.ubuntu.com/ubuntu/p Recise-updates main RESTRICTEDDEB-SRC http://cn.archive.ubuntu.com/ubuntu/precise-updates main restricted
# # N.B. Software from this repository are entirely unsupported by the ubuntu## team. Also, please note this software in universe won't receive any## review or updates from the Ubuntu security Team.deb htt P://cn.archive.ubuntu.com/ubuntu/precise universedeb-src http://cn.archive.ubuntu.com/ubuntu/precise Universedeb Http://cn.archive.ubuntu.com/ubuntu/precise-updates universedeb-src http://cn.archive.ubuntu.com/ubuntu/ Precise-updates Universe
# # N.B. Software from this repository are entirely unsupported by the Ubuntu # # team, and May isn't being under a free licence. Satisfy yourself as to # # Your rights to use the software. Also, please note this software in # # Multiverse won't receive any review or updates from the ubuntu## security team.de b http://cn.archive.ubuntu.com/ubuntu/precise multiversedeb-src Http://cn.archive.ubuntu.com/ubuntu/precise Multiversedeb http://cn.archive.ubuntu.com/ubuntu/precise-updates multiversedeb-src http://cn.archive.ubuntu.com/ Ubuntu/precise-updates Multiverse
# # N.B. Software from this repository is not having been tested as## extensively as that contained in the main release, Alt Hough it includes## Newer versions of some applications which may provide useful features.## Also, please note that Softwa Re in backports won't receive any review## or updates from the Ubuntu security Team.deb Http://cn.archive.ubuntu.com/ub Untu/precise-backports main restricted universe multiversedeb-src http://cn.archive.ubuntu.com/ubuntu/ Precise-backports Main restricted Universe multiverse
Deb Http://cn.archive.ubuntu.com/ubuntu/precise-security main RESTRICTEDDEB-SRC http://cn.archive.ubuntu.com/ Ubuntu/precise-security main Restricteddeb http://cn.archive.ubuntu.com/ubuntu/precise-security universedeb-src Http://cn.archive.ubuntu.com/ubuntu/precise-security Universedeb http://cn.archive.ubuntu.com/ubuntu/ Precise-security MULTIVERSEDEB-SRC http://cn.archive.ubuntu.com/ubuntu/precise-security Multiverse
# # Uncomment the following, lines to add software from Canonical ' s## ' partner ' repository.## This software was not part of Ubuntu, but are offered by Canonical and the## respective vendors as a service to Ubuntu users.# Deb Http://archive.cano Nical.com/ubuntu precise partner# deb-src http://archive.canonical.com/ubuntu precise Partner
# # This software was not a part of Ubuntu, but was offered by third-party## developers the want to ship their latest software. # # Deb Http://extras.ubuntu.com/ubuntu precise main## deb-src http://extras.ubuntu.com/ubuntu precise main
#########################################################################################################
Copy the middle code, rename it to Sources.list and then overwrite the source file, and after using the sudo apt-get updata command, you will soon be done with the update, and then in the installationsudo apt-get install Libglib2.0-dev will succeed.
 And then in the checkDpkg-l|grep glib should have had it,


Under compilationGCC Dello.c-o hello-lglib-2.0 through
Run
./hello
nice! It worked!


So far only the standard output Hello has been run, and the other features inside the library have a long way to go.
recommend a starter URL for a bull man
Http://blog.chinaunix.net/uid-25696269-id-466217.html

Ubuntu Complete Installation GLib experience

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.