Feature #18490


MakeMakefile.pkg_config should accept multiple options

Added by mdalessio (Mike Dalessio) 4 months ago. Updated 3 months ago.

Target version:



When building static libraries it is sometimes necessary to pass multiple flags to pkg-config. Currently, MakeMakefile.pkg_config does not allow this.

A PR has been submitted at

Real-world example

One example of this is the libmagic library which is wrapped by the ruby-magic gem. The ruby-magic gem's extconf.rb needs to pass two options to pkg-config, so that the command executed should be:

pkg-config --libs --static libmagic

(Note that passing only --libs then only --static and merging the results is not sufficient; both must be passed on the same invocation.)

MakeMakefile.pkg_config only supports passing one option to pkg-config today.

Historical context

Prior to Ruby 3.1.0, it was possible to work around this limitation by crafting an options string like so:

pkg_config('libmagic', 'libs --static')

The option parameter would be interpolated into the command template as variable opt:

"#{$PKGCONFIG} --#{opt} #{pkg}

resulting in the desired command string of pkg-config --libs --static libmagic.

However, with commit this hack stopped working because the underlying ruby code is now:

xpopen([*envs, $PKGCONFIG, "--#{opt}", pkg], err:[:child, :out], &:read)

which results in pkg-config returning an error:

"Unknown option --libs --static\n"

Updated by mdalessio (Mike Dalessio) 4 months ago

Pinging @nobu (Nobuyoshi Nakada) for feedback as he is the primary maintainer of mkmf

Updated by nobu (Nobuyoshi Nakada) 4 months ago

Thank you for the report and patch.
It seems fine.
Could you split adding tests of existing methods from the new feature?

Updated by mdalessio (Mike Dalessio) 4 months ago

Thank you for taking the time to review. I've split the commit as you requested:

Updated by mdalessio (Mike Dalessio) 4 months ago

@nobu (Nobuyoshi Nakada), I wanted to check if there was any other feedback on this feature? Thank you again for your time.

Updated by matz (Yukihiro Matsumoto) 4 months ago

  • Assignee set to nobu (Nobuyoshi Nakada)



Actions #6

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed

Also available in: Atom PDF