Question

I'm trying to use cygwin as a build environment under Windows. I have some dependencies on 3rd party packages, for example, GTK+.

Normally when I build under Linux, in my Makefile I can add a call to pkg-config as an argument to gcc, so it comes out like so:

gcc example.c `pkg-config --libs --cflags gtk+-2.0` 

This works fine under Linux, but in cygwin I get:

:Invalid argument
make: *** [example] Error 1

Right now, I am just manually running pkg-config and pasting the output into the Makefile, which is truly terrible. Is there a good way to workaround or fix for this issue?

Make isn't the culprit. I can copy and paste the command line that make uses to call gcc, and that by itself will run gcc, which halts with ": Invalid argument".

I wrote a small test program to print out command line arguments:

for (i = 0; i < argc; i++)
    printf("'%s'\n", argv[i]);

Notice the single quotes.

$ pkg-config --libs gtk+-2.0
-Lc:/mingw/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpang
owin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-
2.0 -lglib-2.0 -lintl

Running through the test program:

$ ./t `pkg-config --libs gtk+-2.0`
'C:\cygwin\home\smo\pvm\src\t.exe'
'-Lc:/mingw/lib'
'-lgtk-win32-2.0'
'-lgdk-win32-2.0'
'-latk-1.0'
'-lgdk_pixbuf-2.0'
'-lpangowin32-1.0'
'-lgdi32'
'-lpangocairo-1.0'
'-lpango-1.0'
'-lcairo'
'-lgobject-2.0'
'-lgmodule-2.0'
'-lglib-2.0'
'-lintl'
'

Notice the one single quote on the last line. It looks like argc is one greater than it should be, and argv[argc - 1] is null. Running the same test on Linux does not have this result.

That said, is there, say, some way I could have the Makefile store the result of pkg-config into a variable, and then use that variable, rather than using the back-tick operator?

Was it helpful?

Solution

That said, is there, say, some way I could have the Makefile store the result of pkg-config into a variable, and then use that variable, rather than using the back-tick operator?

GTK_LIBS = $(shell pkg-config --libs gtk+-2.0)

OTHER TIPS

Are you sure that you're using the make provided by Cygwin? Use

which make
make --version

to check - this should return "/usr/bin/make" and "GNU Make 3.8 [...]" or something similar.

Hmmm... have you tried

make -d

That will give you some (lots) of debugging output.

My guess would be that cygwin's gcc can't handle -Lc:/mingw/lib. Try translating that to a cygwin path.

GTK_LIBS = $(patsubst -Lc:/%,-L/cygdrive/c/%,$(shell pkg-config --libs gtk+-2.0))

The single quote at the end of the "t" output may be an artifact of CRLF translation. Is your pkg-config a cygwin app? The $(shell) solution I posted earlier may help with this, as GNU make seems to be fairly tolerant of different line ending styles.

I had a similar issue and I found a fix here: http://www.demexp.org/dokuwiki/en:demexp_build_on_windows

Take care to put /usr/bin before /cygwin/c/GTK/bin in your PATH so that you use /usr/bin/pkg-config. This is required because GTK's pkg-config post-processes paths, often transforming them in their Windows absolute paths equivalents. As a consequence, tools under cygwin may not understand those paths.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top