Sitemap

Using pkg-config

1 min readDec 14, 2023

--

Press enter or click to view image in full size

So, you are compiling C or C++ code but doesn’t know how to link the libraries so that your header files are recognized as part of the program? Don’t worry for I will teach you some pkg-config commands that you can use to build GTK, poppler, cairo and other C/C++ library applications.

Firstly, you can use ‘pkg-config — list-all’, without the apostrophes, to check which libraries you have installed in your PC that are ready for linking. It will give an alphabetical order response listing all packages.

To use pkg-config during compiling, you can, for example do:

‘g++ -o outputprogram yourcppfile.cpp `pkg-config — libs — cflags gtk4 poppler-glib`’

Get obbeel’s stories in your inbox

Join Medium for free to get updates from this writer.

or

‘gcc -o outputprogram yourcppfile.cpp `pkg-config — libs — cflags gtk4 poppler-glib`’

for a program that uses the GTK GUI library and the pdf rendering library, Poppler.

That will link the libraries and compiler flags to your compiling program.

You can also use ‘$(pkg-config — libs — cflags gtk4 poppler-glib)’ instead of the back-ticks.

That’s it! Now you should be able to use pkg-config to compile your C/C++ programs with included header files.

Leave your Claps if you liked the content. Thank you!

--

--