How to Find Headers and Libraries for C/C++ Programs Using Pkg Config
When learning to program C or C++ beyond a simple "Hello, World" program, one of the hardest things can be to get the code to compile and link properly. If you are trying to use a UI library like GTK, there are many include paths and libraries to specify, which can be tedious at best and frustrating and error-prone at worst. Pkg-config is a utility designed to ease this pain.
This wikihow will assume you want to use headers and libraries associated with gtkmm-2.4 as an example.
Note: Because of wikihow limitations, the title of this wikihow is formatted incorrectly. "Pkg Config" should be pkg-config.
[edit] Steps
- Install pkg-config on your computer. If you are using Linux, it is probably available as an rpm or deb package. e.g.
$sudo apt-get install pkg-config - Type
$pkg-config --help
at the command line. This will show some useful options to use with pkg-config. - Check that you have the right headers and libraries available on your machine:
$pkg-config --list-all | grep gtkmm-2.4
This should produce output like:
gtkmm-2.4 gtkmm - C++ wrapper for GTK+
- Add the following options to your C/C++ project settings or makefile:
- For the compile settings:
`pkg-config --cflags gtkmm-2.4`
- For the link settings:
`pkg-config --libs gtkmm-2.4`
Note the necessity of backquotes (`) surrounding the options.
- For the compile settings:
- Build the program!
[edit] Tips
- If step 3 fails, you will need to install the headers and libraries in the same way you installed pkg-config. e.g.
$sudo apt-get install libgtkmm-2.4-dev










