Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Using pkg-config with qmake

From Wiki
Jump to: navigation, search
Article Metadata
Platform(s): Maemo
Keywords: Qt, qmake, Maemo
Created: gnuton (16 Jun 2010)
Last edited: hamishwillee (24 Jul 2012)


Using pkg-config with qmake

Preface: Who has to read this page?

People who want to add external libs to their Qt applications.

What's pkg-config

pkg-config is a helper tool used when compiling applications and libraries. It helps you insert the correct compiler options on the command line. So, for instance, an application can use

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

rather than hard-coding the location of libs and include files. Manual page is to be found at pkg-config.

How pkg-config works

This utility takes data from .pc files in the /usr/lib/pkgconfig/ directory. Those files are installed by any library development package (eg: libsqlite3-dev).

 [sbox-FREMANTLE_ARMEL: ~] > dpkg -L libsqlite3-dev

Which libs are managed by pkg-config

Usually every linux/Maemo library is managed by pkg-config and it appears in the list of managed packages:

 pkg-config --list-all

How to use pkg-config with qmake

Qt Project files (.pro) contain several variables used by the compiler, such as LIBS and INCLUDE. These variables contain the name and the location of the library required by the linker and the location of the include files used by the compiler.

When qmake creates a Makefile, it takes into account the predefined value of LIBS and INCLUDE coming from a Qt mkspec. The mkspec files are platform specific and they are stored in /usr/share/qt4/mkspecs/platform_name.

Anyway, Mkspecs files just keep Qt libs data. Therefore, a developer who wants to add new libraries has to tell to the compiler where the new libs are located.

This can be easily done by adding 2 lines to the project file:

unix {
    CONFIG += link_pkgconfig
    PKGCONFIG += <pc_file_without_extension>
This page was last modified on 24 July 2012, at 02:11.
211 page views in the last 30 days.