The GNU build system体验教程:Hello world example with Autoconf and Automake
来源:互联网 发布:sqlserver over函数 编辑:程序博客网 时间:2024/05/16 03:08
一、安装GNU构建系统
在安装GNU构建系统之前先介绍四个软件包:
Autoconf:生成configure配置脚本;
Automake:生成makefile模板;
Libtool:用可移植的方式编译无关位置的代码并且构建共享库;
Autotoolset:生成各种模板文件帮助你开发出各种符合GNU代码风格的可移植的源码。
输入以下命令以检查是否安装了最新的版本:
$ autoconf --version$ automake --version$ libtool --version
本教程使用了Autoconf 2.69,Automake 1.15和Libtool 2.4.6。
如果没有以上软件包,请自行安装好。
二、创建需要的文件
在一个空目录下创建以下三个文件(后面会给出下载链接):
hello.c
#include <stdio.h>int main(void){ printf("Howdy world!\n"); return 0;}
要编译的C语言源文件。
Makefile.am
bin_PROGRAMS = hellohello_SOURCES = hello.c
文件的第一行指定了程序的名字,第二行指定了源代码的路径以及文件名。
configure.ac
AC_INIT(hello,0.1)AC_CONFIG_SRCDIR(hello.c)AM_INIT_AUTOMAKEAC_PROG_CCAC_PROG_INSTALLAC_OUTPUT(Makefile)
AC_INIT宏初始化了配置脚本,第一个参数指定了软件包的名字,第二个参数指定了软件包的版本号;
AC_CONFIG_SRCDIR宏指定了源文件的路径以及文件名;
AM_INIT_AUTOMAKE宏声明由Automake自动生成Makefile.in文件(现在不用理解);
AC_PROG_CC宏检查系统可用的编译器,如果源文件为C++请使用AC_PROG_CXX宏;
AC_PROG_INSTALL宏检查系统是否安装了BSD兼容安装工具(BSD compatible install utility);
AC_OUTPUT宏告诉安装脚本从Makefile.in文件生成Makefile文件。
三、输入命令以生成软件包
按顺序输入以下命令:
$ aclocal$ autoconf$ touch README AUTHORS NEWS ChangeLog$ automake -a$ ./configure$ make$ ./hello
aclocal命令安装了一个叫做aclocal.m4的文件;
autoconf命令结合aclocal.m4文件和configure.ac文件生成configure脚本;
touch命令在调用automake命令之前创建了包括READEME文件在内的几个Automake需要的文件;
automake命令检查是否缺少了必要的文件并且生成Makefile.in文件;
./configure命令分析系统是否安装了软件所依赖的软件和库;
make命令编译软件;
./hello命令执行程序。
然后可以输入# make install命令安装软件,输入# make uninstall命令卸载软件。
最后输入make distcheck生成hello-0.1.tar.gz发布软件。
四、安装、使用、卸载软件包
按顺序输入以下命令:
$ gunzip hello-0.1.tar.gz$ tar xf hello-0.1.tar$ cd hello-0.1$ ./configure$ make# make install$ ./hello# make uninstall
本软件包可以不用# make install与# make uninstall。
hello-0.1.tar.gz下载链接:
Hello world example with Autoconf and Automake.
五、进一步学习
提供以下链接以供进一步学习Autotools与GNU构建系统
GNU Automake
Autotools Tutorial for Beginners
The GNU configure and build system
Learning the GNU development tools
- The GNU build system体验教程:Hello world example with Autoconf and Automake
- GNU build system automake autoconf等快速入门
- The GNU configure and build system
- The GNU Build System
- GNU hello学习笔记(1)——autoconf和automake
- GNU hello学习笔记(1)——autoconf和automake
- Using Automake and Autoconf with C++
- Gnu autoconf 和 automake
- GNU automake/autoconf 入门
- “Hello World” Example with AspectDNG
- The GNU configure and build system-configure的详细介绍
- The GNU configure and build system-configure的详细介绍
- 读GNU Autoconf, Automake, and Libtool后感
- 读GNU Autoconf, Automake, and Libtool后感
- automake hello world 使用教程 例子
- automake hello world 使用教程 例子
- automake hello world 使用教程 例子
- FreeMarker(FTL) Hello World Tutorial with Example
- IOS学习之:网络数据的XML解析
- C++封装继承多态总结
- hdoj -1874 畅通工程续
- Jam的计数法
- android碰到未捕获异常重启
- The GNU build system体验教程:Hello world example with Autoconf and Automake
- KVM虚拟机无法连网分析
- 晶体振荡器的选择种类(晶体振荡器与晶体谐振器的区别)
- JAVA 反射笔记 Actionbar设置样式
- ubuntu tun/tap安装
- Android 查看更多 TextView实现
- 【转】RxJava教程大集合
- IOS学习:ios开发之数据的持久化存储机制
- linux内存管理--实际分配函数 buffered_rmqueue