Makefile自动生成(autotools工具的使用)

autotools是个系列工具,首先确认你的Ubuntu系统是否安装了以下工具(可以通过which命令查看):

aclocal

autoscan

autoconf

autoheader

automake

---------------------------------------------------------------------------------

安装方法:

[email protected]:~$ sudo apt-get install autoconf

装完后,用which 命令查看

如下:

[email protected]:~$ which aclocal

/usr/bin/aclocal

[email protected]:~$ which autoscan

/usr/bin/autoscan

[email protected]:~$ which autoconf

/usr/bin/autoconf

[email protected]:~$ which auto header

[email protected]:~$ automake

automake: `configure.ac‘ or `configure.in‘ is required

[email protected]:~$ which automake

/usr/bin/automake

------------------------------------------------------------------------------

下面开始来生成一个Makefile:

建立以下代码文件:

hello.cxx  hello.h

以下直接贴出我的操作过程:

[email protected]:~/work/test$ autoscan

[email protected]:~/work/test$ ls

autoscan.log  configure.scan  hello.cxx  hello.h

[email protected]:~/work/test$ mv configure.scan configure.ac

[email protected]:~/work/test$ ls

autoscan.log  configure.ac  hello.cxx  hello.h

[email protected]:~/work/test$ gedit configure.ac

[email protected]:~/work/test$ aclocal

[email protected]:~/work/test$ ls

aclocal.m4      autoscan.log  configure.ac~  hello.h

autom4te.cache  configure.ac  hello.cxx

[email protected]:~/work/test$ autoconf

[email protected]:~/work/test$ ls

aclocal.m4      autoscan.log  configure.ac   hello.cxx

autom4te.cache  configure     configure.ac~  hello.h

[email protected]:~/work/test$ autoheader

[email protected]:~/work/test$ ls

aclocal.m4      autoscan.log  configure     configure.ac~  hello.h

autom4te.cache  config.h.in   configure.ac  hello.cxx

[email protected]:~/work/test$ touch makefile.am

[email protected]:~/work/test$ gedit makefile.am

[email protected]:~/work/test$ automake -a

configure.ac:6: installing `./install-sh‘

configure.ac:6: installing `./missing‘

makefile.am: installing `./depcomp‘

[email protected]:~/work/test$ ls

aclocal.m4      config.h.in   configure.ac~  hello.h      makefile.am~

autom4te.cache  configure     depcomp        install-sh   makefile.in

autoscan.log    configure.ac  hello.cxx      makefile.am  missing

[email protected]:~/work/test$ ./configure

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checking for a thread-safe mkdir -p... /bin/mkdir -p

checking for gawk... no

checking for mawk... mawk

checking whether make sets $(MAKE)... yes

checking for g++... g++

checking whether the C++ compiler works... yes

checking for C++ compiler default output file name... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

checking for suffix of object files... o

checking whether we are using the GNU C++ compiler... yes

checking whether g++ accepts -g... yes

checking for style of include used by make... GNU

checking dependency style of g++... gcc3

checking for gcc... gcc

checking whether we are using the GNU C compiler... yes

checking whether gcc accepts -g... yes

checking for gcc option to accept ISO C89... none needed

checking dependency style of gcc... gcc3

configure: creating ./config.status

config.status: creating makefile

config.status: creating config.h

config.status: executing depfiles commands

[email protected]:~/work/test$ make hello

g++ -DHAVE_CONFIG_H -I.     -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.cxx

mv -f .deps/hello.Tpo .deps/hello.Po

g++  -g -O2   -o hello hello.o

[email protected]:~/work/test$

其中:

[email protected]:~/work/test$ gedit configure.ac编辑configure.ac内容为

#                                               -*- Autoconf -*-

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

AC_PREREQ([2.68])

AC_INIT(hello,1.0)

AM_INIT_AUTOMAKE(hello,1.0)

AC_CONFIG_SRCDIR([hello.cxx])

AC_CONFIG_HEADERS([config.h])

# Checks for programs.

AC_PROG_CXX

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])

AC_OUTPUT

[email protected]:~/work/test$ gedit makefile.am编辑makefile.am的内容为:

AUTOMAKE_OPTIONS=foreign

bin_PROGRAMS=hello

hello_SOURCES=hello.cxx

最后的执行.configure我们得到了makefile文件,使用make命令就输出了可执行文件hello

时间: 2024-08-11 06:02:43

Makefile自动生成(autotools工具的使用)的相关文章

Makefile自动生成工具-----autotools的使用(详细)

相信每个学习Linux的人都知道Makefile,这是一个很有用的东西,但是编写它是比较复杂,今天介绍一个它的自动生成工具,autotools的使用.很多GNULinux的的软件都是用它生成Makefile的,包括我们非常熟悉的Linux内核源代码. 1.准备: 需要工具 autoscan aclocal autoheader automake autoconf auto make 在终端敲入命令,哪个没有安装哪个,一般是第一个autoscan没有,其它的我用的Ubuntu10.04下全部都有

Makefile自动生成头文件依赖

前言 Makefile自动生成头文件依赖是很常用的功能,本文的目的是想尽量详细说明其中的原理和过程. Makefile模板 首先给出一个本人在小项目中常用的Makefile模板,支持自动生成头文件依赖. CC = gcc CFLAGS = -Wall -O INCLUDEFLAGS = LDFLAGS = OBJS = seq.o TARGETS = test_seq .PHONY:all all : $(TARGETS) test_seq:test_seq.o $(OBJS) $(CC) -o

C/C++ makefile自动生成工具(comake2,autotools,linux),希望能为开源做点微薄的贡献!

序 在linux下C或C++项目开发,Makefile是必备的力气,但是发现手写很麻烦. 在百度有个comake2工具,用于自动生成Makefile工具,而在外边本想找一个同类工具,但发现很难做到,只发现有个类似的智能生成工具autotools,但是操作比较麻烦,奔着“一人学习,大家共享”的原则,手动写了一个工具类,帮助自己和大家生成现成的c或者cpp框架. 代码比较简单,希望我们能一起改善下. git路径:https://github.com/chuanshanjia/ccpp/blob/ma

linux 商业项目 makefile 自动生成工具Autotools的使用

我们在平时的学习中要编译我们写的源代码生成可执行文件,大家都知道用gcc编译工具就可以完成任务,更复杂一点的,如果我们编写的文件比较多,那单纯在linux环境下写gcc命令进行编译就显得有点效率太低了,这时我们肯定想到写一个makefile来完成这样稍微复杂的编译过程,我想很多人也确实是是这样做的,所以我们回去学习makefile 的语法,其实如果编译 的文件量再多一些,文件之间的依赖关系更复杂一些,那么我们编写一个正确的,效率高的makefile也不是一件很容易的事情吧.其实我之前是有体验过这

Makefile 自动生成头文件的依赖关系 .

最近在看一本书<Windows游戏编程大师技巧> (Tricks of Windows Game Programming Gurus). 第一章给出了一个打砖块小游戏的示例程序. 包括三个文件: blackbox.h, blackbox.cpp和freakout.cpp (600行代码, 对于Windows C++程序来说还好, 没有让我freak out…). blackbox.cpp封装了部分DirectDraw, 提供了一些更傻瓜化的初始化DirectDraw, 画点, 画方框的工具函数

linux makefile自动生成

一.Linux Makefile介绍 Linux Makefile是用于自动编译和链接的,一个工程有很多文件组成,每一个文件的改变都会导致工程的重新链接,但是不是所有的文件都需要重新编译,Linux Makefile中纪录有文件的信息,在make时会决定在链接的时候需要重新编译哪些文件. Linux Makefile的宗旨就是:让编译器知道要编译一个文件需要依赖其他的哪些文件.当那些依赖文件有了改变,编译器会自动的发现最终的生成文件已经过时,而重新编译相应的模块. Linux Makefile的

Velt中的Makefile自动生成

VELT的全称是Visual EmbedLinuxTools,它是一个与visual gdb类似的visual studio插件,用以辅助完成Linux开发.利用这个插件,将可以在visual studio的IDE中进行Linux应用程序的开发(包括编译和调试),也可以进行uboot和linux内核的编译,并根据编译时的错误信息正确定位到源码.目前的版本是0.2.1,支持vs2012/vs2013/vs2015. 下载地址:http://pan.baidu.com/s/1nt6bOOL Velt

SpringBoot与Mybatis整合(包含generate自动生成代码工具,数据库表一对一,一对多,关联关系中间表的查询)

链接:https://blog.csdn.net/YonJarLuo/article/details/81187239 自动生成工具只是生成很单纯的表,复杂的一对多,多对多要自己在xml中写! 添加mybatis的generator插件: 链接:https://blog.csdn.net/readyyy/article/details/85935365 原文地址:https://www.cnblogs.com/wskb/p/11582711.html

mybatis-generator自动生成代码工具

1.在项目的配置文件中放入配置文件mybatis-generator-config.xml   根据情况修改下配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://myb