Cross-compiling LibGTop2

By | January 22, 2013

When you have a Linux embedded system and you’re programming in C (that is quite common), sometimes you need to calculate inside a program the resources usage for a given process ID such as CPU or memory; or in general you could need to know the network bandwith or the list of mounted devices.
The most commmon way for gathering this data is to parse out the files inside /proc/, but this can be tedious. There is a discussion at stackoverflow about it.

An alternative, if you already have or can install glib2, is to use LibGTop that “is a library to get system specific data such as CPU and Memory Usage and information about running Processes”.

Compiling and installing it in a PC is not a problem as the nice Beyond Linux From Scratch guide shows, but for cross-compiling it is not straight forward.

Here’s the simple procedure:

Package
glibtop-2.28.4

Requirements
This library is built on top of other libraries such as glib2 and intltool. I wrote a post some time ago that could be helpul for compiling glib2. If you’re using buildroot, it already builds glib2 for you if selected.

Environment configuration
As normal, set the environment variables that make our life easier. Change them according to your needs. These settings are for an ARM based processor:

Configuration
Since I have an embedded system without graphical interface and it’s a single-core processor, I don’t need X nor the SMP parameter. Adjust it according to your system:

The examples/ directory doesn’t build properly unless you modify the Makefile. If you don’t want to compile this directory you can skip it by adding to the above configure command the parameter –with-examples.

Let’s assume that you want the examples/ directory:
Edit the file examples/Makefile:
Set the LIBS variables to the following value:

Compilation and installation

Using LibGTop2
For compiling and linking a program that uses LibGTop2 you need to include the header files and the libraries. Here’s a fragment of the Makefile I use:

That’s it. Have fun!

Leave a Reply

Your email address will not be published. Required fields are marked *