pkg-config sometimes strips -I/opt/local/include from its output

Joshua Root jmr at macports.org
Tue Dec 8 08:51:55 UTC 2020


So here's a "fun" thing I discovered while updating python:

% pkg-config libffi --cflags-only-I
-I/opt/local/include

% env CPATH=/opt/local/include pkg-config libffi --cflags-only-I


(Second command prints a blank line.)

This appears to be a deliberate behaviour designed to avoid including
paths that will be searched by the compiler by default. And to be fair,
it's probably OK a lot of the time. Python, however, uses the output to
determine whether it's using the system libffi on macOS.

There is another variable PKG_CONFIG_ALLOW_SYSTEM_CFLAGS which prevents
the affected paths from being removed from the output. I'm not sure
whether it would be a good idea to set that all the time in base.

Hopefully this information will help someone else avoid being driven
slightly crazy when pkg-config behaves differently in a port's configure
script than it does in a shell.

- Josh


More information about the macports-dev mailing list