Install pkg-config on Ubuntu 24.04

Install pkg-config on Ubuntu 24.04

The pkg-config is a tool that helps manage compiler and linker options for libraries. It simplifies the process of building applications by providing the necessary options required to compile and link against installed development packages. This tutorial explains how to install pkg-config on Ubuntu 24.04.

Prepare environment

Before starting, ensure that the GCC compiler and relevant development headers are available. In this example, the uuid-dev package is used to demonstrate how pkg-config works with a library:

sudo apt install -y gcc uuid-dev

Install pkg-config

Run the following command to update package lists:

sudo apt update

Install pkg-config:

sudo apt install -y pkg-config

Confirm the installation by checking the pkg-config version:

pkg-config --version

Testing pkg-config

Create a sample C source file:

nano main.c

Add the following code:

#include <stdio.h>
#include <uuid/uuid.h>

int main() {
    uuid_t id;
    uuid_generate(id);

    char str[37];
    uuid_unparse(id, str);

    printf("%s\n", str);

    return 0;
}

Compile the program by supplying the required options with pkg-config:

gcc main.c -o test $(pkg-config --cflags --libs uuid)

Run the program:

./test

If everything is configured correctly, a generated UUID string will be printed to the terminal.

Uninstall pkg-config

To completely remove pkg-config and clean up unused dependencies, run the following command:

sudo apt purge --autoremove -y pkg-config

Leave a Comment

Cancel reply

Your email address will not be published.