学习记录:
目录
project
|---base
| |--fun.c
| |--fun.h
| |--hello.c
| |--hello.h
|---src
|--main.c
主要使用automake,libtools进行编译辅助,base目录下是调用库,src目录是应用程序
文件内容如下:
fun.h
fun.c
hello.h
hello.c
main.c
使用如下:
1。在project目录下建立Makefile.am文件
注意: 依赖文件库文件在前面
在base目录下新建Makefile.am文件
在src目录下新建Makefile.am文件
2.在project目录下
运行autoscan检测生成configure.scan..(出错不用理会),命名为configure.in文件
$autoscan
$mv configure.scan configure.in
查看生成文件configure.in如下
#
修改为
3.在目录下新建autogen.sh脚本
$chmod a+x autogen.sh
给脚本执行权限
4.运行脚本
$./autogen.sh
5.运行生成的configure文件
$./configure
6.$make
后面就可以像我们平时编译开源的源码包一样,进行configure,make ,make clean等操作
PS:本文只是使用step by step,具体为什么这样做,请查看相应automake帮助.
目录
project
|---base
| |--fun.c
| |--fun.h
| |--hello.c
| |--hello.h
|---src
|--main.c
主要使用automake,libtools进行编译辅助,base目录下是调用库,src目录是应用程序
文件内容如下:
fun.h
- ##fun.h
- #ifndef __FUN__H__
- #define __FUN__H__
- int add(int a, int b);
- #endif
- int add(int a, int b)
- {
- return a+b;
- }
- #ifndef __HELLO__H__
- #define __HELLO__H__
- void output(char *ss);
- #endif
- #include <stdio.h>
- void output(char *ss)
- {
- printf("HELLO %s/n",ss);
- return;
- }
- #include <stdio.h>
- #include "hello.h"
- #include "fun.h"
- int main()
- {
- output("world");
- printf("Test Value:%d/n",add(1,2));
- return 0;
- }
1。在project目录下建立Makefile.am文件
- SUBDIRS = base src
在base目录下新建Makefile.am文件
- lib_LTLIBRARIES = libtest.la
- libtest_la_SOURCES = fun.c fun.h hello.c hello.h
- INCLUDES= -I$(top_srcdir)/base
- bin_PROGRAMS = test
- test_SOURCES = main.c
- test_LDADD = $(top_builddir)/base/libtest.la
运行autoscan检测生成configure.scan..(出错不用理会),命名为configure.in文件
$autoscan
$mv configure.scan configure.in
查看生成文件configure.in如下
#
- #
- # 利用libtool自动生成动态库
- #
- 1. autoscan命令在当前目录生成configure.scan文件, 内容为:
- # -*- Autoconf -*-
- # Process this file with autoconf to produce a configure script.
- AC_PREREQ(2.59)
- AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
- AC_CONFIG_SRCDIR([src/main.c])
- AC_CONFIG_HEADER([config.h])
- # Checks for programs.
- AC_PROG_CC
- # Checks for libraries.
- # Checks for header files.
- # Checks for typedefs, structures, and compiler characteristics.
- # Checks for library functions.
- AC_CONFIG_FILES([Makefile
- base/Makefile
- src/Makefile])
- AC_OUTPUT
- #
- # 利用libtool自动生成动态库
- #
- 1. autoscan命令在当前目录生成configure.scan文件, 内容为:
- # -*- Autoconf -*-
- # Process this file with autoconf to produce a configure script.
- AC_PREREQ(2.59)
- AC_INIT(test, 1.0, rufeng18@yahoo.com.cn) ###
- AC_CONFIG_SRCDIR([src/main.c])
- AM_CONFIG_HEADER([config.h]) ###
- AM_INIT_AUTOMAKE(test, 1.0) ###
- # Checks for programs.
- AC_PROG_CC
- AM_PROG_LIBTOOL ###
- # Checks for libraries.
- # Checks for header files.
- # Checks for typedefs, structures, and compiler characteristics.
- # Checks for library functions.
- AC_CONFIG_FILES([Makefile
- base/Makefile
- src/Makefile])
- AC_OUTPUT
- #! /bin/sh
- #Regenerate the files autoconf /automake
- libtoolize --force --automake
- rm -f config.cache
- rm -f config.log
- aclocal
- autoheader
- autoconf
- automake -ac --foreign --add-missing --copy
给脚本执行权限
4.运行脚本
$./autogen.sh
5.运行生成的configure文件
$./configure
6.$make
后面就可以像我们平时编译开源的源码包一样,进行configure,make ,make clean等操作
PS:本文只是使用step by step,具体为什么这样做,请查看相应automake帮助.