使用 autotools 为共享库正确安装 config.h [英] Correct installation of config.h for shared library using autotools

查看:29
本文介绍了使用 autotools 为共享库正确安装 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.

在整个程序和库源中,自动标头生成的 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

在顶级Makefile.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,通过在 CPPFLAGSfoo_CPPFLAGSAC_SUBST 中传递相关定义来Makefile.am 用于源构建,或 AC_SUBSTfoo.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.

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

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