How to use pkg-config in Make

前端 未结 1 420
走了就别回头了
走了就别回头了 2020-12-08 15:35

I want to compile the simplest GTK program. I can compile it using the command line:

gcc $(pkg-config --cflags --libs gtk+-3.0)  main.c -o main.o

相关标签:
1条回答
  • 2020-12-08 15:41

    There are two issues.

    First, your CFLAGS line is wrong: you forgot to say gtk+-3.0 in the pkg-config part, so pkg-config will spit out an error instead:

    CFLAGS=-g -Wall -Wextra $(pkg-config --cflags gtk+-3.0)
    

    Second, and more important, $(...) is intercepted by make itself for variable substitution. In fact, you've seen this already:

    SOURCES=$(wildcard *.c)
    EXECUTABLES=$(patsubst %.c,%,$(SOURCES))
    
    all: $(EXECUTABLES)
    

    is all done by make.

    There are two things you can do.

    First, you can use `...` instead, which does the same thing ($(...) is newer shell syntax).

    CFLAGS=-g -Wall -Wextra `pkg-config --cflags gtk+-3.0`
    LDFLAGS=`pkg-config --libs gtk+-3.0`
    

    Second, since you seem to be using GNU make, you can use the shell substitution command, which was shown in the answer Basile Starynkevitch linked above:

    CFLAGS=-g -Wall -Wextra $(shell pkg-config --cflags gtk+-3.0)
    LDFLAGS=$(shell pkg-config --libs gtk+-3.0)
    
    0 讨论(0)
提交回复
热议问题