1
votes

I'm trying to compile a gtk program on PowerShell so that I can use pkg-config's output as input to gcc but gcc is taking the whole output as a single command line option and return the error:

gcc.exe: error: unrecognized command line option '-mms-bitfields -pthread -mms-bitfields -IC:/gtk/include/gtk-3.0 -IC tk/include/cairo -IC:/gtk/include -IC:/gtk/include/pango-1.0 -IC:/gtk/include/atk-1.0 -IC:/gtk/include/cairo -IC:/gtk clude/pixman-1 -IC:/gtk/include -IC:/msys/opt/include -IC:/msys/opt/include/freetype2 -IC:/msys/opt/include -IC:/msys t/include/libpng16 -IC:/gtk/include -IC:/gtk/include/freetype2 -IC:/gtk/include -IC:/gtk/include/libpng16 -IC:/gtk/in de/gdk-pixbuf-2.0 -IC:/gtk/include/libpng16 -IC:/gtk/include/glib-2.0 -IC:/gtk/lib/glib-2.0/include -LC:/gtk/lib -lgt -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lz -lpangowin32-1.0 -lp ocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl'

the command line I'm using:

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

I've also tried:

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

either return same result. How do I fix this?

1
gcc hello.c -o hello '--%' $(pkg-config.exe --cflags --libs gtk+-3.0)user4003407
Worked fine, thanks. You can post it as answer so I can accept.Jack

1 Answers

2
votes

It seems that pkg-config.exe --cflags --libs gtk+-3.0 command return its output as single line and thus in PowerShell it is parsed as single string object. And when string with spaces (actual rule more complex and version dependent) passed to native application, then PowerShell tries to be helpful and add quotes, so it be interpreted as single argument. One way to prevent it is to use '--%' "operator":

gcc hello.c -o hello '--%' $(pkg-config.exe --cflags --libs gtk+-3.0)

Note that it is not actually --% operator, so it not make rest of the line to be interpreted literally. Actually it is just string with value --%.

The "magic" happens because when PowerShell command line builder for native applications encounter --% string it disables automatic quoting for arguments with spaces for any remaining arguments. And it also passes them thru [Environment]::ExpandEnvironmentVariables to resolve environment variables in %VariableName% form.