使用 PKG_CHECK_MODULES 时,autoconf 生成的 Makefile 不会传递库标头的标志 [英] autoconf-generated Makefile does not pass flags for library headers when using PKG_CHECK_MODULES

查看:49
本文介绍了使用 PKG_CHECK_MODULES 时,autoconf 生成的 Makefile 不会传递库标头的标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目依赖于一个库(更准确地说是 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_LDFLAGSAM_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆