Correct quoting for pkg-config on Windows

Dan Nicholson dbn.lists at
Sat Apr 6 11:27:47 PDT 2013

On Fri, Jan 25, 2013 at 8:58 AM, Niklas Gürtler <profclonk at> wrote:
> Hi Dan,
> when running a pkg-config.exe on windows and passing its output to
> (e.g.) a gcc.exe the arguments have to be correctly quoted (if they
> contain spaces or other special characters) so the gcc.exe will see the
> correct arguments.
> For example, if pkg-config outputs this: -IC:/Program Files/mylib/inc
> gcc won't correctly get the path, so it has to be quoted like this:
> "-IC:/Program Files/mylib/inc"
> This is similar to how it works on Unix, but the quoting works
> differently on Windows, and that patch generates correct windows-quoted
> strings.
> The patch adds double quotes if neccessary (i.e. when the string
> contains spaces), escapes existing double quotes, and doubles the
> backslashes that come before double quotes (see the examples in my
> original mail). The #ifdef makes sure that this only happens when
> compiling for windows.

OK, I think I get it now, and having played around a bit on Windows I
see what the issue is. Quoting on Windows is pretty crazy, I guess
mostly because of the poor decision to use \ as the path separator.
Here's some info I found online.

Anyway, I don't think I want to make this the default on native Win32
builds of pkg-config. The reason is that most pkg-config users on
Windows (I believe) are using MSYS, which uses a bash shell as
interpreter. pkg-config's parsing is all geared towards shell and
works fine there. I'd actually like this if you could add this as an
option (perhaps --dos-quoting or something) and not make it Windows
only. Then it could be tested from any platform since I don't believe
it depends on any Windows APIs.

What do you think? I can help you get that going, if you'd like. It
also wouldn't be a bad idea to open a bug about this.


More information about the pkg-config mailing list