Using `pkg-config` as a command line argument in cygwin / msys bash

I am trying to use cygwin as a build environment under Windows. I have some dependencies on third-party packages like GTK +.

Usually, when I build on Linux, in my Makefile I can add a call to pkg-config as a gcc argument, so it looks like this:

  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

Now I just run pkg-config manually and paste the output into the Makefile, which is really terrible. Is there a good way to work around or fix this problem?

Make is not a criminal. I can copy and paste the command line, which makes use for calling gcc, and on its own will run gcc, which stops with ": Invalid argument".

I wrote a small test program to output command line arguments:

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

Pay attention to 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

Test program execution:

  $ ./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'
 ''

Pay attention to one single quote in the last line. It seems that argc alone is bigger than it should be, and argv [argc - 1] is null. Running the same test on Linux does not have this result.

However, is there, say, in some way I can make the Makefile save the result of pkg-config in a variable and then use this variable instead of using the back-tick operator?

+4
source share
6 answers

However, is there, say, in some way I can make the Makefile save the result of pkg-config in a variable and then use this variable instead of using the back-tick operator?

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

+6
source

Are you sure you are using make provided by Cygwin? Use

 which make make --version 

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

+4
source

Hmmm ... have you tried

 make -d 

This will give you some (many) debug output.

+2
source

I assume cygwin gcc cannot handle -Lc: / mingw / lib. Try translating this to the cygwin path.

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

A single quotation mark at the end of the "t" output may be an artifact of the CRLF translation. Is your pkg-config a cygwin application? The $ (shell) solution I posted earlier can help with this, since GNU make seems pretty tolerant of different line ending styles.

+1
source

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

Make sure to put / usr / bin in front of / cygwin / c / GTK / bin in your PATH so that you use / usr / bin / pkg -config. This is necessary because GTK pkg-config post-processes paths, often converting them to its Windows absolute path equivalents. As a result, cygwin tools may not understand these paths.

+1
source

Source: https://habr.com/ru/post/1276923/


All Articles