使用PKG_CHECK_MODULES时,autoconf生成的Makefile不会为库头传递标志 [英] autoconf-generated Makefile does not pass flags for library headers when using PKG_CHECK_MODULES
问题描述
我的项目依赖于一个库(更确切地说是GTK +),所以我在configure.ac
中添加了以下配置:
My project depends upon a library (more precisely, GTK+) so I added the following configurations in my configure.ac
:
PKG_CHECK_MODULES([GTK], [gtk+-2.0])
AC_SUBST([GTK_CFLAGS])
AC_SUBST([GTK_LIBS])
我的Makefile.am
是:
bin_PROGRAMS = secretary
secretary_SOURCES = secretary.c
依次,我的secretary.c
如下:
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
gtk_main();
return 0;
}
但是,当我运行make
时(当然,在调用./configure
之后),出现了此错误:
However, when I run make
(of course, after calling ./configure
) I got this error:
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT secretary.o -MD -MP -MF \
.deps/secretary.Tpo -c -o secretary.o secretary.c
secretary.c:1:21: fatal error: gtk/gtk.h: File or directory not found.
我想念什么?为什么autoconf无法将正确的标志传递给gcc?
What am I missing? Why does autoconf not pass the correct flags to gcc?
推荐答案
使用PKG_CHECK_MODULES
时,需要在Makefile.am
中指定标志.最简单的方法是将其添加到AM_LDFLAGS
和AM_CPPFLAGS
:
When you use PKG_CHECK_MODULES
, you need to specify the flags in Makefile.am
. The easiest way is to add it to AM_LDFLAGS
and AM_CPPFLAGS
:
AM_LDADD = @GTK_LIBS@
AM_CPPFLAGS = @GTK_CFLAGS@
如果您想更具体一点,可以添加:
If you want to be more specific, you can instead add:
secretary_LDADD = @GTK_LIBS@
secretary_CPPFLAGS = @GTK_CFLAGS@
完全不使用PKG_CHECK_MODULES
并让用户通过通常的机制(分配LDFLAGS
或在标准位置安装库)来指定库的位置可能更容易.
It is probably easier to not use PKG_CHECK_MODULES
at all and let the user specify the location of the libraries through the usual mechanism (assigning LDFLAGS
or installing the libraries in a standard location).
这篇关于使用PKG_CHECK_MODULES时,autoconf生成的Makefile不会为库头传递标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!