GUN automake,autoconf写Makefile(一)

摘要

 网上这方面的文章不少,也有很多错误的,如何去伪存真也不容易,英文好的同学最好还是看官方的介绍,毕竟是原版专业的,最近刚好用到这个工具,写下我自己的认识,抛砖引玉希望能给大家一点参考。

首先还是从helloword一步一步来。

内容

  1. automake,autoconf安装
  2. Helloword程序
  3. automake生成Makefile

一.automake,autoconf 安装

  
  hello word之旅前需要准备上面几个安装包,都可以在GUN官网上面下。

二.Helloword程序

OK,安装完,我们来写helloword,这个大家熟悉,做IT入门招式,万变不离其宗。新建hello.cpp

#include <iostream>
using namespace std;
int main(int argc,char *argv[])
{
    std::cout<<"hello automake"<<endl;
    return 0;
}

三. automake生成Makefile

  1. autoscan
  2. 修改configure.scan,重命名configure.in
  3. 写Makefile.am
  4. 执行aclocal
  5. autoconf
  6. automake --add-missing
  7. ./configure --prefix=/home/app  && make && make install
下面给大家介绍一下上面helloword生成Makefile.

1. autoscan 生成configure.scan

2. 修改configure.scan

mv configure.scan configure.in

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([hello], [1.1.0], [417356935@qq.com])
#AC_CONFIG_SRCDIR([hello.cpp])
#AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE() 
# Checks for programs.
AC_PROG_CXX

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_OUTPUT(Makefile)
~

3. 写Makefile.am文件

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.cpp

hello目录下面就有下面几个文件,下面就是几个命令步骤了。

4. 执行aclocal

有如下告警,不做理会,生成aclocal.m4。

<span style="font-family:SimSun;font-size:12px;">[centos@server hello]$aclocal
aclocal: warning: autoconf input should be named 'configure.ac', not 'configure.in'</span>

5. 执行autoconf生成configure

6. 运行automake --add-missing,生成Makefile.in文件

7.运行./configure --prefix=/home/app/hello, 生成Makefile

[centos@server hello]$make
g++ -DPACKAGE_NAME=\"hello\" -DPACKAGE_TARNAME=\"hello\" -DPACKAGE_VERSION=\"1.0.1\" -DPACKAGE_STRING=\"hello\ 1.0.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"hello\" -DVERSION=\"1.0.1\" -I.     -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.cpp
mv -f .deps/hello.Tpo .deps/hello.Po
g++  -g -O2   -o helloword hello.o  

[centos@server hello]$./helloword 
hello automake

这样helloword的Makefile就写完了。这只是开始,后面动态库,静态库,工程的目录架构后续在介绍。

附件:automake流程图








  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值