windows 在 cygwin/msys bash 下使用 `pkg-config` 作为命令行参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/101767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using `pkg-config` as command line argument under cygwin/msys bash
提问by smo
I'm trying to use cygwin as a build environment under Windows. I have some dependencies on 3rd party packages, for example, GTK+.
我正在尝试使用 cygwin 作为 Windows 下的构建环境。我对 3rd 方软件包有一些依赖,例如 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:
通常,当我在 Linux 下构建时,在我的 Makefile 中,我可以添加对 pkg-config 的调用作为 gcc 的参数,因此结果如下:
gcc example.c `pkg-config --libs --cflags gtk+-2.0`
This works fine under Linux, but in cygwin I get:
这在 Linux 下工作正常,但在 cygwin 中我得到:
: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?
现在,我只是手动运行 pkg-config 并将输出粘贴到 Makefile 中,这真的很糟糕。是否有解决此问题的好方法?
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".
制造不是罪魁祸首。我可以复制并粘贴用于调用 gcc 的命令行,它本身将运行 gcc,它会以“:无效参数”停止。
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.
注意最后一行的单引号。看起来 argc 比应有的大一,并且 argv[argc - 1] 为空。在 Linux 上运行相同的测试没有这个结果。
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?
也就是说,是否有某种方法可以让 Makefile 将 pkg-config 的结果存储到一个变量中,然后使用该变量,而不是使用反引号运算符?
回答by Adam Mitz
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?
也就是说,是否有某种方法可以让 Makefile 将 pkg-config 的结果存储到一个变量中,然后使用该变量,而不是使用反引号运算符?
GTK_LIBS = $(shell pkg-config --libs gtk+-2.0)
GTK_LIBS = $(shell pkg-config --libs gtk+-2.0)
回答by Tobias Kunze
Are you sure that you're using the make provided by Cygwin? Use
你确定你使用的是 Cygwin 提供的 make 吗?用
which make
make --version
to check - this should return "/usr/bin/make" and "GNU Make 3.8 [...]" or something similar.
检查 - 这应该返回“/usr/bin/make”和“GNU Make 3.8 [...]”或类似的东西。
回答by Tobias Kunze
Hmmm... have you tried
嗯……你试过了吗
make -d
That will give you some (lots) of debugging output.
这将为您提供一些(大量)调试输出。
回答by Adam Mitz
My guess would be that cygwin's gcc can't handle -Lc:/mingw/lib. Try translating that to a cygwin path.
我的猜测是 cygwin 的 gcc 无法处理 -Lc:/mingw/lib。尝试将其转换为 cygwin 路径。
GTK_LIBS = $(patsubst -Lc:/%,-L/cygdrive/c/%,$(shell pkg-config --libs gtk+-2.0))
回答by Adam Mitz
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.
"t" 输出末尾的单引号可能是 CRLF 翻译的产物。您的 pkg-config 是 cygwin 应用程序吗?我之前发布的 $(shell) 解决方案可能对此有所帮助,因为 GNU make 似乎对不同的行结束样式相当宽容。
回答by allialliallialli
I had a similar issue and I found a fix here: http://www.demexp.org/dokuwiki/en:demexp_build_on_windows
我有一个类似的问题,我在这里找到了一个修复: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.
注意将 /usr/bin 放在 PATH 中的 /cygwin/c/GTK/bin 之前,以便使用 /usr/bin/pkg-config。这是必需的,因为 GTK 的 pkg-config 后处理路径,通常在它们的 Windows 绝对路径等效项中转换它们。因此,cygwin 下的工具可能无法理解这些路径。