views:

1641

answers:

5

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?

+3  A: 

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.

Tobias Kunze
Yup, updated the question to reflect this.
smo
+1  A: 

Hmmm... have you tried

make -d

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

Tobias Kunze
Yeah, thanks, it is definitely running gcc, but gcc is having the problem. Updated the question.
smo
+3  A: 

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)

Adam Mitz
+1  A: 

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))
Adam Mitz
Nah, it's actually mingw gcc -- I neglected to mention this.
smo
Yeah, that would have been nice to know :). Mingw gcc seems to be fine with C:/ paths.
Adam Mitz
+1  A: 

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.

Adam Mitz
I agree it is probably related to crlf.The pkg-config is actually from mingw, as well. I had tried dropping in the cygwin pkg-config but that was using the cygwin paths which mingw didn't like, but I did confirm that the cygwin pkg-config does not create an extra null argv.
smo
Interesting... I don't have a pkg-config in my mingw installation to test. Must have been an optional package (I have the gcc 3.4.5 mingw).
Adam Mitz
I think I tracked down the pkg-config as coming from the GTK+ bundle:http://www.gtk.org/download-windows.html
smo