通过configure.ac文件生成copnfigure文件

本文详细介绍了如何在Linux系统中利用automake和autoconf生成configure文件,包括步骤、常见问题及解决方法。首先,通过autoscan扫描源代码,接着运行aclocal、autoconf、autoheader、automake等命令。在过程中可能会遇到如AC_PROG_LIBTOOL未定义的问题,解决方法是安装libtool并重新运行autoreconf。文章还提供了一个实例,演示了从创建测试代码到生成configure的完整过程。
摘要由CSDN通过智能技术生成

步骤:

aclocal
autoconf
autoheader
automake --add-missing


问题1:

configure.ac:18: error: possibly undefined macro: AC_PROG_LIBTOOL

                     If this token and others are legitimate, please use m4_pattern_allow.
                     See the Autoconf documentation.
                     autoreconf: /usr/bin/autoconf failed with exit status: 1

解决方法:

centos下:yum install libtool


问题2:

configure.ac:188:required file 'ltmain.sh'

解决方法:

autoreconf  -ivf


一、生成configure过程中各文件之间的关系图

二、详细介绍

autoscan: 扫描源代码以搜寻普通的可移植性问题,比如检查编译器,库,头文件等,生成文件configure.scan,它是configure.ac的一个雏形。

aclocal:根据已经安装的宏,用户定义宏和acinclude.m4文件中的宏将configure.ac文件所需要的宏集中定义到文件 aclocal.m4中。aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configure.ac”

automake:将Makefile.am中定义的结构建立Makefile.in,然后configure脚本将生成的Makefile.in文件转换 为Makefile。如果在configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOOL,它会调用libtoolize,否则它 会自己产生config.guess和config.sub

autoconf:将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。

三、实例

1.测试代码(定义两个文件hello.h和hello.c)

复制代码
/*hello.c*/
#include <iostream>
#include "hello.h"

using namespace std;

int main()
{
    CHello a;
    return 0;
}
复制代码
复制代码
/*hello.h*/
#ifndef __HELLO_H__
#define __HELLO_H__

#include<iostream>
using namespace std;

class CHello
{
public:
    CHello(){ cout<<"Hello!"<<endl;}
    ~CHello(){ cout<<"Bye!"<<endl;}
};

#endif
复制代码

2.操作步骤

(1)安装依赖的包
[root@bogon autoconfig]# yum -y install automake autoconf

automake包括:aclocal、automake等

autoconf包括:autoscan、autoco

`configure.ac` 文件是一个用于生成 `configure` 脚本的模板文件,通常位于开源项目的根目录中。这个 `configure` 脚本用于检测系统环境并配置项目以适应该环境,它是由 `autoconf` 工具处理 `configure.ac` 文件生成的。要运行 `configure.ac` 文件,你需要遵循以下步骤: 1. 安装 `autoconf` 和 `automake` 工具(如果尚未安装): - 在Debian/Ubuntu系统上,可以使用命令 `sudo apt-get install autoconf automake` 安装。 - 在Red Hat/CentOS系统上,可以使用命令 `sudo yum install autoconf automake` 安装。 - 在macOS上,可以使用Homebrew通过命令 `brew install autoconf automake` 安装。 2. 打开终端,切换到包含 `configure.ac` 文件的目录。 3. 执行以下命令生成 `configure` 脚本: ``` aclocal && autoconf && autoheader && automake --add-missing --foreign ``` 这些命令的含义如下: - `aclocal`:生成 `aclocal.m4` 文件,它是 `autoconf` 的宏文件。 - `autoconf`:根据 `configure.ac` 文件生成 `configure` 脚本。 - `autoheader`:生成用于生成 `Makefile.in` 模板文件的 `config.h.in` 文件。 - `automake`:生成 `Makefile.in` 文件,这些文件用于 `make` 命令编译项目。 4. 在项目根目录中,你将看到生成的 `configure` 脚本。运行此脚本,可以按如下方式: ``` ./configure [选项] ``` 其中 `[选项]` 是一些可选的参数,比如 `--prefix=/指定目录` 用于指定安装路径等。 确保你在一个有足够权限的环境中操作,特别是在安装软件时,可能需要管理员权限。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值