简体   繁体   中英

Is it possible to use an environment variable in a pkg-config.pc file?

I'm trying to use a library libfoo.so that will be installed in $(LIBDIR)/foo/ where $(LIBDIR) is an environment variable that can be different based on the build setup.

In order for other components to correctly link with this library, they need to have the correct LDFLAGS set, namely they need to have -L$(LIBDIR)/foo -lfoo set. In order to make this a bit more generic, I would like to add a libfoo.pc file to libfoo with these flags set. My file currently has the following contents:

Name: libfoo
Description: Example library
Version: 1.0.0
Libs: -L$(LIBDIR)/foo -lfoo

My other component which uses libfoo has the following simplified makefile:

all:
    $(CC) bar.c -o out $(shell pkg-config --libs libfoo)

The library is correctly found by pkg-config, but running make gives the following error:

$ make
cc bar.c -o out -L$(LIBDIR)/foo -lfoo
/bin/sh: LIBDIR: command not found

In other words, $(LIBDIR) is not expanded into the value that is set as an environment variable. Is it possible to use environment variables or makefile variables in.pc files?

It looks like using environment variables inside pkg-config.pc files is not possible.

As a workaround I will instead add a prefix variable to the.pc file which is filled in or overwritten by a script before my bar component is compiled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM