使用自动工具正确安装共享库的config.h [英] Correct installation of config.h for shared library using autotools

查看:471
本文介绍了使用自动工具正确安装共享库的config.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在转换一个使用autotools构建系统的C ++程序来使用共享库,介绍使用libtool。大多数程序功能被放置在由主程序加载的共享库中,使得将来其他程序可以访问公共代码。

I am converting a C++ program which uses the autotools build system to use a shared library, introducing the use of libtool. Most of the program functionality is being placed in the shared library, which is loaded by the main program, so that the common code can be accessed by other programs in future.

在整个程序和库源中,autoheader生成的 config.h 与通常的宏一起使用:

Throughout the program and library sources the autoheader generated config.h is used with the usual macro:

#if HAVE_CONFIG_H
# include <config.h>
#endif

在configure.ac中,我使用宏来生成它:

In configure.ac I use the macro to generate it:

AC_CONFIG_HEADERS([config.h])

我的问题是,我需要安装 config.h 以便其他人能够使用我的库,如果是这样,

My question is, do I need to install config.h for others to be able to use my library, and if so, what is the appropriate way to do it, and should it be renamed to avoid conflicts etc?

我发现的最多信息是这里:

The most information I have found on this is here:

http://www.openismus.com/documents/ linux / building_libraries / building_libraries#installingheaders

但这几乎不是官方来源。

But this is hardly an official source.

推荐答案

如果影响接口,则需要安装 config.h 。实际上,如果头部需要 #define ,而不仅仅是 .cc

You will need to install config.h if it affects the interface. In practical terms, if the #define's are required by the header(s), not just the .cc implementation / compilation units.

如果 config.h 有问题,您可以在 AC_CONFIG_HEADERS 宏。例如 AC_CONFIG_HEADERS([foo_config.h])

If config.h is a problem, you can specify another name in the AC_CONFIG_HEADERS macro. e.g., AC_CONFIG_HEADERS([foo_config.h]).

安装标题的最简单方法,假设 automake ,具有:

The easiest way to install the header, assuming automake, is with:

nodist_include_HEADERS = foo_config.h

.am 。 nodist 前缀告诉automake foo_config.h 是生成的,而不是随包一起分发。

in the top-level Makefile.am. the nodist prefix tells automake that foo_config.h is generated rather than distributed with the package.

如果不使用automake,请在 $ includedir 中安装 foo_config.h $ exec_prefix / include 可以说是一个生成头的更正确的位置,但实际上前面的位置很好。

If not using automake, install foo_config.h in $includedir. $exec_prefix/include is arguably a more correct location for a generated header, but in practice the former location is fine.

我通过在 config.h > CPPFLAGS 或 foo_CPPFLAGS 以及 AC_SUBST Makefile.am 用于源代码生成,或 AC_SUBST foo.h.in -时间。很多 config.h 是测试生成的噪声。它需要更多的基础设施,但它是我喜欢的。我不会推荐这种方法,除非你对自动工具很舒服。

I avoid using config.h, by passing relevant definitions in CPPFLAGS or foo_CPPFLAGS along with AC_SUBST to Makefile.am for source builds, or AC_SUBST to foo.h.in to generate headers at configure-time. A lot of config.h is test-generated noise. It requires more infrastructure, but it's what I prefer. I wouldn't recommend this approach unless you're comfortable with the autotools.

这篇关于使用自动工具正确安装共享库的config.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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