在Ubuntu下使用autotools生成Makefile
来源:互联网 发布:mysql主键自增长 重置 编辑:程序博客网 时间:2024/05/23 07:24
相信在Linux环境下做过项目的人,都会知道Makefile的重要性。它能够帮助我们完成很多的编译工作,节约我们自己去编译的时间。Makefile的重要性这里就不在强调了!Windows下的IDE都自动生成了Makefile,因此不需要自己再去写Makefile,所以习惯了在Windows下编程的人突然在Linux下编程是不适应的。
既然Windows下能够自动生成Makefile,那么Linux下有没有这样的工具呢?
答案是有的,应该在做一个大的项目的时候,不可能都靠人来写Makefile,这样太麻烦了!很多GNULinux的的软件都是用它生成Makefile的,包括我们非常熟悉的Linux内核源代码。Linux下自动生成Makefile的工具有autotools、qmake等。(玩过QT的人应该对qmake十分熟悉)
一、autotools的安装步骤
下面主要是针对autotools工具来讲,先从安装步骤开始吧。
我的环境是Ubuntu 14.04版本,Ubuntu安装工具十分方便,用apt命令即可。
sudo apt-get install autoconf安装完成之后,使用which命令查看是否安装成功。因为autotools是个系列工具,安装包相互直接存在依赖。
zqj@ubuntu:~$ which aclocal/usr/bin/aclocalzqj@ubuntu:~$ which autoscan/usr/bin/autoscanzqj@ubuntu:~$ which autoconf/usr/bin/autoconfzqj@ubuntu:~$ which autoheader/usr/bin/autoheaderzqj@ubuntu:~$ which automake/usr/bin/automake这样就安装完成了,接下来讲讲怎么使用autotools吧!
二、autotools的使用
接下来我们写个测试代码吧!
我写的测试代码结构如下:tree命令查看
.└── Test ├── include │ └── head.h └── Main └── main.cpphead.h
/*****************************************************Copyright (C) 2017-2018 All rights reserved.File name : head.hVersion : v1.0 Author : ZhengqijunDate : 2017年04月10日 星期一 17时31分05秒Description : 头文件Funcion List : *****************************************************/#ifndef __HEAD_H__#define __HEAD_H__#include <iostream>using namespace std;#endif //__HEAD_H__main.cpp
/*****************************************************Copyright (C) 2017-2018 All rights reserved.File name : main.cppVersion : v1.0 Author : ZhengqijunDate : 2017年04月10日 星期一 17时32分20秒Description : 主函数Funcion List : main()*****************************************************/#include "../include/head.h"int main(){ cout << "hello world!" << endl; return 0;}
autotools的使用步骤如下:
1、使用autoscan命令生成autoscan.log configure.scan两个文件。zqj@ubuntu:~/2017/0410/Test$ autoscanzqj@ubuntu:~/2017/0410/Test$ lsautoscan.log configure.scan include Main
2、使用cp命令生成configure.ac文件。
zqj@ubuntu:~/2017/0410/Test$ cp configure.scan configure.ac zqj@ubuntu:~/2017/0410/Test$ lsautoscan.log configure.ac configure.scan include Main
找到这句 AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
其中,FULL-PACKAGE-NAME为程序名称,VERSION为当前版本,BUG-REPORT-ADDRESS为bug汇报地址。
这里我改为:(根据自己的实际情况)
AC_INIT(Main, 0.0.1, xxx@xx.com)然后在AC_INIT()后面添加一句AM_INIT_AUTOMAKE,在AC_OUTPUT()前面添加一句AC_CONFIG_FILES([Makefile])。如下所示:
4、执行aclocal命令生成aclocal.m4和autom4te.cache文件。
zqj@ubuntu:~/2017/0410/Test$ aclocalzqj@ubuntu:~/2017/0410/Test$ lsaclocal.m4 autoscan.log configure.scan Mainautom4te.cache configure.ac include
5、制作Makefile.am文件,因为automake这个命令需要用到这个配置文件。
# Makefile.amAUTOMAKE_OPTIONS = foreignbin_PROGRAMS = mainmain_SOURCES = include/head.h Main/main.cppmain_CPPFLAGS = -I include/
6、执行autoheader命令生成config.h.in文件。
7、使用touch命令生成automake必须文件。
touch NEWS README AUTHORS ChangeLogautomake必须文件:
install-sh、missing、INSTALL、NEWS、README、AUTHORS、ChangeLog、COPYING、depcomp
执行automake -a的时候会自动生成
install-sh、missing、INSTALL、COPYING、depcomp
其它文件就需要自己手动添加了。可以使用touch命令
8、执行automake -a命令生成其它文件。
zqj@ubuntu:~/2017/0410/Test$ automake -azqj@ubuntu:~/2017/0410/Test$ lsaclocal.m4 ChangeLog configure.scan INSTALL Makefile.inAUTHORS compile COPYING install-sh missingautom4te.cache config.h.in depcomp Main NEWSautoscan.log configure.ac include Makefile.am README
9、执行autoconf命令生成configure文件。
zqj@ubuntu:~/2017/0410/Test$ autoconfzqj@ubuntu:~/2017/0410/Test$ lsaclocal.m4 compile COPYING Main READMEAUTHORS config.h.in depcomp Makefile.amautom4te.cache configure include Makefile.inautoscan.log configure.ac INSTALL missingChangeLog configure.scan install-sh NEWS
10、执行./configure命令进行测试。
zqj@ubuntu:~/2017/0410/Test$ ./configure checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for a thread-safe mkdir -p... /bin/mkdir -pchecking for gawk... nochecking for mawk... mawkchecking whether make sets $(MAKE)... yeschecking whether make supports nested variables... yeschecking for g++... g++checking whether the C++ compiler works... yeschecking for C++ compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yeschecking for style of include used by make... GNUchecking dependency style of g++... gcc3checking for gcc... gccchecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking whether gcc understands -c and -o together... yeschecking dependency style of gcc... gcc3checking that generated files are newer than configure... doneconfigure: creating ./config.statusconfig.status: creating Makefileconfig.status: creating config.hconfig.status: executing depfiles commands
11、执行make命令生成可执行文件。
zqj@Zqj-ubuntu:~/2017/0410/Test$ makemake all-ammake[1]: Entering directory `/home/zqj/2017/0410/Test'g++ -DHAVE_CONFIG_H -I. -I include/ -g -O2 -MT main-main.o -MD -MP -MF .deps/main-main.Tpo -c -o main-main.o `test -f 'Main/main.cpp' || echo './'`Main/main.cppmv -f .deps/main-main.Tpo .deps/main-main.Pog++ -g -O2 -o main main-main.o make[1]: Leaving directory `/home/zqj/2017/0410/Test'注意:如果make出错,没有生成可执行文件。那么下次make编译前,先使用make clean清除中间文件,再进行重新编译!(make出错可能是配置文件写的有问题Makefile.am)
- 在Ubuntu下使用autotools生成Makefile
- 在Ubuntu下使用autotools生成Makefile
- Linux下使用Autotools生成Makefile
- Ubuntu16.04下使用autotools生成Makefile
- 使用Autotools生成Makefile
- 使用autotools生成makefile
- 使用autotools生成Makefile
- 转:使用autotools生成Makefile文件(ubuntu 8.04)
- 转:使用autotools生成Makefile文件(ubuntu 8.04)
- 使用autotools简单生成Makefile
- autotools使用(自动生成Makefile)
- 使用autotools自动生成makefile
- 使用autotools工具自动生成makefile文件
- ubuntu12.04使用autotools自动生成makefile
- Makefile自动生成工具-----autotools的使用
- 自动生成Makefile----autotools的使用
- Makefile自动生成(autotools工具的使用)
- autotools使用(自动生成makefile)
- PaginationSupport加强版的分页代码
- java基础(二)----流程控制语句跳转控制语句
- JSTL之<c:forEach>
- 将汉字转化成Unicode编码
- 【Java8】Guava——Predicate
- 在Ubuntu下使用autotools生成Makefile
- eclipse中使用jstl
- 关于Windows XP SP2 x86上不支持的两个C++11
- jdbc获取表中列名
- 网狐【客户端配置杂项】
- sql语句
- 迷宫
- Linux 的gcc gdb
- jQuery插件linkButton