Ubuntu 18.04 install Glib library and configure Codeblocks

Ubuntu 18.04 install Glib library and configure Codeblocks

1. Install Glib Library

(1) Let's update the next source first

sudo apt-get update

(2) Next install Glib

sudo apt-get install libglib2.0-*

(3) Check if Glib is installed successfully

dpkg -l | grep glib

The display is as follows:

ii  gir1.2-dbusmenu-glib-0.4:amd64             16.04.1+18.04.20171206-0ubuntu2                 amd64        typelib file for libdbusmenu-glib4
ii  gir1.2-geocodeglib-1.0:amd64               3.25.4.1-4ubuntu0.18.04.1                       amd64        introspection data for geocode-glib library
ii  gir1.2-glib-2.0:amd64                      1.56.1-1                                        amd64        Introspection data for GLib, GObject, Gio and GModule
ii  gir1.2-packagekitglib-1.0                  1.1.9-1ubuntu2.18.04.5                          amd64        GObject introspection data for the PackageKit GLib library
ii  gir1.2-snapd-1:amd64                       1.49-0ubuntu0.18.04.1                           amd64        Typelib file for libsnapd-glib1
ii  gir1.2-upowerglib-1.0:amd64                0.99.7-2ubuntu0.18.04.1                         amd64        GObject introspection data for upower
ii  glib-networking:amd64                      2.56.0-1                                        amd64        network-related giomodules for GLib
ii  glib-networking-common                     2.56.0-1                                        all          network-related giomodules for GLib - data files
ii  glib-networking-services                   2.56.0-1                                        amd64        network-related giomodules for GLib - D-Bus services
ii  libappstream-glib8:amd64                   0.7.7-2                                         amd64        GNOME library to access AppStream services
ii  libavahi-glib1:amd64                       0.7-3.1ubuntu1.2                                amd64        Avahi GLib integration library
ii  libdbus-glib-1-2:amd64                     0.110-2                                         amd64        deprecated library for D-Bus IPC
ii  libdbus-glib2.0-cil                        0.6.0-1build1                                   all          CLI implementation of D-Bus (GLib mainloop integration)
ii  libdbus-glib2.0-cil-dev                    0.6.0-1build1                                   all          CLI implementation of D-Bus (GLib mainloop integration) - development files
ii  libdbusmenu-glib4:amd64                    16.04.1+18.04.20171206-0ubuntu2                 amd64        library for passing menus over DBus
ii  libgeocode-glib0:amd64                     3.25.4.1-4ubuntu0.18.04.1                       amd64        geocoding and reverse geocoding GLib library using Nominatim
ii  libglib-object-introspection-perl          0.044-2                                         amd64        Perl bindings for gobject-introspection libraries
ii  libglib-perl                               3:1.326-1build1                                 amd64        interface to the GLib and GObject libraries
ii  libglib2.0-0:amd64                         2.56.4-0ubuntu0.18.04.6                         amd64        GLib library of C routines
ii  libglib2.0-bin                             2.56.4-0ubuntu0.18.04.6                         amd64        Programs for the GLib library
ii  libglib2.0-cil                             2.12.40-2                                       amd64        CLI binding for the GLib utility library 2.12
ii  libglib2.0-cil-dev                         2.12.40-2                                       amd64        CLI binding for the GLib utility library 2.12
ii  libglib2.0-data                            2.56.4-0ubuntu0.18.04.6                         all          Common files for GLib library
ii  libglib2.0-dev:amd64                       2.56.4-0ubuntu0.18.04.6                         amd64        Development files for the GLib library
ii  libglib2.0-dev-bin                         2.56.4-0ubuntu0.18.04.6                         amd64        Development utilities for the GLib library
ii  libglib2.0-doc                             2.56.4-0ubuntu0.18.04.6                         all          Documentation files for the GLib library
ii  libglib2.0-tests                           2.56.4-0ubuntu0.18.04.6                         amd64        GLib library of C routines - installed tests
ii  libjson-glib-1.0-0:amd64                   1.4.2-3                                         amd64        GLib JSON manipulation library
ii  libjson-glib-1.0-common                    1.4.2-3                                         all          GLib JSON manipulation library (common files)
ii  libmbim-glib4:amd64                        1.18.0-1~ubuntu18.04.1                          amd64        Support library to use the MBIM protocol
ii  libmm-glib0:amd64                          1.10.0-1~ubuntu18.04.2                          amd64        D-Bus service for managing modems - shared libraries
ii  libpackagekit-glib2-18:amd64               1.1.9-1ubuntu2.18.04.5                          amd64        Library for accessing PackageKit using GLib
ii  libpoppler-glib8:amd64                     0.62.0-2ubuntu2.10                              amd64        PDF rendering library (GLib-based shared library)
ii  libpulse-mainloop-glib0:amd64              1:11.1-1ubuntu7.4                               amd64        PulseAudio client libraries (glib support)
ii  libqmi-glib5:amd64                         1.22.0-1.2~ubuntu18.04.1                        amd64        Support library to use the Qualcomm MSM Interface (QMI) protocol
ii  libsnapd-glib1:amd64                       1.49-0ubuntu0.18.04.1                           amd64        GLib snapd library
ii  libupower-glib3:amd64                      0.99.7-2ubuntu0.18.04.1                         amd64        abstraction for power management - shared library

My Glib library is installed with 2.56.4.

2. Install Codeblocks

Direct installation:

sudo apt-get install codeblocks  

There will be a shortcut after installation:

3. Configure Codeblocks

This configuration is complex. If it is not configured, the following situation will occur:

The specific configuration is as follows:
(1) First of all, we create a Project (if you don't use Codeblocks, you can search for other materials here. There are many on the Internet. I saw it on station B, here I just talk about how to configure it.)
(2) After creation, open main.c and change the code to the following:

#include <glib.h>
int main()
{
	g_print("Hello China!\n");
	return 0;
}

Because we're using the Glib library, change to the code above.
(3) Next, make the relevant configuration:
We open the Project build options in the menu bar above, as shown in the following figure:



Type in these two places: (pay attention to copying mine here, because this is not a simple single quotation mark, but an inverted single quotation mark)

`pkg-config --cflags glib-2.0`

Then OK.

Next, open the Settings Compiler in the menu bar, as shown in the following figure:


Find this place and enter:

`pkg-config --cflags --libs glib-2.0 gthread-2.0 gio-2.0`

Our configuration is OK.

***Note: such a configuration should be carried out every time we create a new Project. * * *

4.Hello China

Let's see the effect of the operation:

This is the end of the whole process! Thank you.
If there are other ways of friends, you can leave a message below and give more advice.

Tags: network sudo JSON Ubuntu

Posted on Tue, 09 Jun 2020 02:07:08 -0400 by frontlines