Using pkg-config as compiler and linker flags

From AcrodusWiki
Revision as of 09:03, 3 December 2024 by Alex (talk | contribs) (Created page with "Came across pkg-config files for the first time when using gtk4. The below extract is the makefile for that hello world test. <pre> CFLAGS = -Wall -g `pkg-config --cflags gtk4` LDFLAGS = `pkg-config --libs gtk4` all: gtk_test.c gcc -o gtk_test gtk_test.c $(CFLAGS) $(LDFLAGS) clean: rm -f *~ rm -f *.o rm -f gtk_test </pre> Main thing here is the addition of the compiler and linker flags at the top. These use the shell environment variab...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Came across pkg-config files for the first time when using gtk4. The below extract is the makefile for that hello world test.

CFLAGS = -Wall -g `pkg-config --cflags gtk4`
LDFLAGS = `pkg-config --libs gtk4`

all: gtk_test.c
        gcc -o gtk_test gtk_test.c $(CFLAGS) $(LDFLAGS)

clean:
        rm -f *~
        rm -f *.o
        rm -f gtk_test

Main thing here is the addition of the compiler and linker flags at the top. These use the shell environment variable PKG_CONFIG_PATH to look for pkg-config files "*.pc" that specify meta data on how to compile and link in the library. I had to find the location of the gtk4.pc file and add it to the PKG_CONFIG_PATH variable with the below commands.

sudo find -type f -name "gtk.pc"
export PKG_CONFIG_PATH=/usr/lib