GNU autotools作用:收集系统配置信息并自动生成Makefile文件。
GNU autotools主要包括三个工具:autoconf、automake、libtool。
生成可执行文件:
主要步骤:
1.开发者要书写的文件主要是configure.in和Makefile.am这两个文件
2.运行autoscan检测源文件生成configure.scan并修改成configure.in
3.编辑configure.in
4.由aclocal命令生成aclocal.m4
5.运行autoconf生成configure脚本
6.运行autoheader生成config.h.in文件
7.创建并编辑Makfile.am
8.运行automake生成makefile.in 有时候可能要加automake --add-missing
9.运行configure脚本生成Makefile
10.make
11.运行可执行程序main
同一个目录
1.写好源码main.c hello.c hello.h
[root@localhost 1]# ls
hello.c hello.h main.c
[root@localhost 1]# cat main.c
#include <stdio.h>
int main(void)
{
printf("main start!\n");
print();
return 0;
}
[root@localhost 1]# cat hello.c
#include "hello.h"
void print(void)
{
char buf[32] = "123";
strcat(buf, "456");
printf("%s\n", buf);
printf("hello,world!\n");
return ;
}
[root@localhost 1]# cat hello.h
#ifndef __HELLO_H__
#define __HELLO_H__
#include <stdio.h>
#include <string.h>
void print(void);
#endif
2.执行命令:autoscan
[root@localhost 1]# autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[root@localhost 1]# ls
autoscan.log configure.scan hello.c hello.h main.c
3.编辑configure.scan
[root@localhost 1]# vim configure.scan
//只增加这2项:
AM_INIT_AUTOMAKE(main, 1.0)
AC_OUTPUT(Makefile)
[root@localhost 1]# mv configure.scan configure.in
4.aclocal
[root@localhost 1]# aclocal
[root@localhost 1]# ls
aclocal.m4 autoscan.log hello.c main.c autom4te.cache configure.in hello.h
5.autoconf
[root@localhost 1]# autoconf