Portably include GLib headers in autoconf/automake

不羁岁月 提交于 2019-12-09 11:22:38

问题


I need to include the GLib headers for a project that is built with an autoconf-based system for portability.

How can I safely import the GLib headers in a portable manner? I know about pkg-config, but that is not entirely portable (since some systems don't have it and I would prefer to only rely on autoconf for configuration).


回答1:


The GLib 2.22 INSTALL file states that pkg-config is a requirement for installing this library. I am not being GLib (pun intended!); statement of this requirement is one of the first things on the top of the INSTALL file.

From the text surrounding it is unclear whether pkg-config is needed to compile GLib itself, however it is clear that GLib 2.22 authors do not intend for any users to compile against GLib without having pkg-config. In particular, GLib's make install will install .pc files appropriately.

For platform portability, instruct the user to set $PKG_CONFIG_PATH appropriately.




回答2:


By using the PKG_CHECK_MODULES macro, Autoconf-generated configure scripts can retrieve pkg-config data automatically. As an example, adding this line to your configure.ac file:

PKG_CHECK_MODULES([DEPS], [glib-2.0 >= 2.24.1])

will cause the resulting configure script to ensure that the installed version of glib-2.0 is greater than or equal to version 2.24.1 as well as append to variables DEPS_CFLAGS and DEPS_LIBS the output of pkg-config --cflags glib-2.0 and pkg-config --libs glib-2.0, respectively. You then use the $(DEPS_CFLAGS) and $(DEPS_LIBS) variables in the _CFLAGS and _LDADD primaries:

bin_PROGRAMS = hello

hello_CFLAGS = $(DEPS_CFLAGS)
hello_SOURCES = hello.c
hello_LDADD = $(DEPS_LIBS)


来源:https://stackoverflow.com/questions/1732822/portably-include-glib-headers-in-autoconf-automake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!