使用autotools工具用configure、make、make install编译安装linux工程的详细步骤

转载tmxkwzy 最后发布于2016-11-24 10:20:15 阅读数 3245  收藏
 

autotools是个系列工具,主要由autoconf、automake、perl语言环境和m4等组成,所包含的命令有5个:

下图是autotools使用的流程图:

autotools的安装:

  1. apt-get install autoconf  automake  autotools-dev m4

autotools使用简单实例如下:

  • 准备程序源代码

    1. mkdir demo_conf
    2. vi hello.cpp

    内容如下:

    1. #include <iostream>
    2. using namespace std;
    3. int main(){
    4. cout << "hello\n";
    5. }
  • 使用autoscan命令,扫描工作目录,生成configure.scan 文件
    1. $ autoscan
    2. $ ls
    3. autoscan.log  configure.scan  hello.cpp
  • 将configure.scan文件重命名为configure.ac(或configure.in),并做适当修改。在configure.ac文件中,#号开始的是行注释,其他都是m4宏命令;configure.ac里面的宏的主要作用是侦测系统
    1. $ mv configure.scan configure.ac
    2. vi configure.ac

    修改后的内容如下:

    1. #                                               -*- Autoconf -*-
    2. # Process this file with autoconf to produce a configure script.
    3. AC_PREREQ([2.68])
    4. AC_INIT(hello, 1.0, zhunian0322@163.com)
    5. AC_CONFIG_SRCDIR([hello.cpp])
    6. AC_CONFIG_HEADERS([config.h])
    7. AM_INIT_AUTOMAKE(hello,1.0)
    8. # Checks for programs.
    9. AC_PROG_CXX
    10. # Checks for libraries.
    11. # Checks for header files.
    12. # Checks for typedefs, structures, and compiler characteristics.
    13. # Checks for library functions.
    14. AC_CONFIG_FILES([Makefile])
    15. AC_OUTPUT

    configure.ac文件说明:

    1. AC_PREREQ   声明本文要求的autoconf版本.如本例中的版本2.68
    2. AC_INIT     用来定义软件的名称、版本、作者E-mail等
    3. AC_CONFIG_SRCDIR    用来侦测所制定的源码文件是否存在,确定源码目录的有效性。此处为当前目录下的hello.cpp
    4. AC_CONFIG_HEADERS   用于生成config.h文件,以便autoheader命令使用
    5. AM_INIT_AUTOMAKE    是通过手动添加的,他是automake所必备的宏,用于指定软件名和软件版本号
    6. AC_PROC_CXX         用来指定编译器。此处是g++  AC_PROC_CC是gcc
    7. AC_CONFIG_FILES     用于生成相应的Makefile文件
    8. AC_OUTPUT           用来设定configure 所要产生的文件,如果是Makefile,configure 会把它检查出来的结果带入makefile.in文件产生何时的Makefile。使用automake时,还需要一些其他的参数,这些额外的宏用aclocal工具产生
  • 使用aclocal命令,扫描configure.ac文件生成aclocal.m4文件,该文件主要处理本地的宏定义,它根据已经安装的宏\用户定义宏和acinclude.m4文件中的宏将configure.ac文件需要的宏集中定义到aclocal.m4中
    1. $ aclocal
    2. $ ls
    3. aclocal.m4  autom4te.cache  autoscan.log  configure.ac  hello.cpp
  • 使用autoconf命令生成configure文件.这个命令将configure.ac文件中的宏展开,生成configure脚本。
    1. $ autoconf
    2. $ ls
    3. aclocal.m4  autom4te.cache  autoscan.log  configure  configure.ac  hello.cpp
  • 使用autoheader命令生成config.h.in文件.该命令通常会中acconfig.h 文件中复制用户附加的符号定义
    1. $ autoheader
    2. $ ls
    3. aclocal.m4      autoscan.log  configure     hello.cpp
    4. autom4te.cache  config.h.in   configure.ac
  • 手工创建Makefile.am 文件。automake工具会根据configure.in中的参量把Makefile.am转换成Makefile.in文件
    1. $ vi Makefile.am

    增加一下内容:

    1. AUTUMAKE_OPTIONS = foreign
    2. bin_PROGRAMS = hello
    3. hello_SOURCES = hello.cpp

    Makefile.am文件内容说明

    1. AUTOMAKE_OPTIONS 为设置automake 的选项.由于GNU对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则automake执行时会报错.automake提供了3种软件等级:foreign、gnu、gnits,供用户选择。默认级别是gnu。
    2. bin_PROGRAMS 定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开
    3. hello_SOURCES  定义“hello”这个可以执行程序所需的原始文件。如果“hello”这个程序是由多个源文件所产生的,则必须把它所用到的所有源文件都列出来,并用空格隔开。如果要定义多个可执行程序,那么需要对每个可执行程序建立对应的file_SOURCES
  • 使用automake 命令生成Makefile.in 文件.使用选项"--add-missing" 可以让automake自动添加一些必须的脚本文件
    1. $ automake --add-missing
    2. configure.ac:8: installing `./install-sh'; error while making link: Operation not supported
    3. configure.ac:8: installing `./missing'; error while making link: Operation not supported
    4. Makefile.am: installing `./INSTALL'; error while making link: Operation not supported
    5. <pre name="code" class="plain">Makefile.am: required file `./NEWS' not found
    6. Makefile.am: required file `./README' not found
    7. Makefile.am: required file `./AUTHORS' not found
    8. Makefile.am: required file `./ChangeLog' not found

    Makefile.am: installing `./COPYING' using GNU General Public License v3 file; error while making link: Operation not supportedMakefile.am: Consider adding the COPYING file to the version control systemMakefile.am: for your code, to avoid questions about which license your project uses.Makefile.am: installing `./depcomp'; error while making link: Operation not supported说明:

    1. configure.ac:8: installing `./install-sh'; error while making link: Operation not supported
    2. configure.ac:8: installing `./missing'; error while making link: Operation not supported
    3. Makefile.am: installing `./depcomp'; error while making link: Operation not supported
    4. ##因为把工程放在FAT32分区上,而它不支持link.需要挪到ext3上
    1. Makefile.am: required file `./NEWS' not found
    2. Makefile.am: required file `./README' not found
    3. Makefile.am: required file `./AUTHORS' not found
    4. Makefile.am: required file `./ChangeLog' not found
    5. ##使用touch 命令创建这4个文件
    1. $ cp -rvf ../demo_conf/  /home/gino/
    2. $ cd /home/gino/demo_conf/
    3. $ touch NEWS
    4. $ touch README
    5. $ touch AUTHORS
    6. $ touch ChangeLog
    7. $ automake --add-missing
    8. $ ls
    9. aclocal.m4      autoscan.log  config.h.in    configure     hello      install-sh   Makefile.in  README
    10. AUTHORS         ChangeLog     config.log     configure.ac  hello.cpp  Makefile     missing      stamp-h1
    11. autom4te.cache  config.h      config.status  depcomp       hello.o    Makefile.am  NEWS
  • 使用configure命令,把Makefile.in 变成Makefile
    1. $ ./configure
    2. checking for a BSD-compatible install... /usr/bin/install -c
    3. checking whether build environment is sane... yes
    4. checking for a thread-safe mkdir -p... /bin/mkdir -p
    5. checking for gawk... no
    6. checking for mawk... mawk
    7. checking whether make sets $(MAKE)... yes
    8. checking for g++... g++
    9. checking whether the C++ compiler works... yes
    10. checking for C++ compiler default output file name... a.out
    11. checking for suffix of executables...
    12. checking whether we are cross compiling... no
    13. checking for suffix of object files... o
    14. checking whether we are using the GNU C++ compiler... yes
    15. checking whether g++ accepts -g... yes
    16. checking for style of include used by make... GNU
    17. checking dependency style of g++... gcc3
    18. configure: creating ./config.status
    19. config.status: creating Makefile
    20. config.status: creating config.h
    21. config.status: config.h is unchanged
    22. config.status: executing depfiles commands

Makefile的用法

  • make 命令,用来执行编译代码,默认执行"make all"命令.
  • make clean 命令清除编译时的obj文件.
  • make install 命令把目标文件安装到系统中.
  • make uninstall 命令把目标文件从系统中卸载.
  • make dist 命令将程序和相关的文档打包为一个压缩文档,以供发布.
  • make -n   非执行模式,输出所有执行命令,但不执行.
  • make -c   读取Makefile之前改变到指定目录
  • make -h   显示所有make选项
 

使用autotools工具用configure、make、make install编译安装linux工程的详细步骤的更多相关文章

  1. ./configure && make && make install 编译安装和卸载 (Linux)

    ./configure && make && make install 编译安装和卸载 (Linux) 正常的编译安装/卸载:   源码的安装一般由3个步骤组成:配置( ...

  2. Linux ./configure && make && make install 编译安装和卸载

    正常的编译安装/卸载: 源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install).   configure文件是一个可执行的脚本文件,它有很多选项, ...

  3. Linux下./configure && make && make install 编译安装和卸载

    正常的编译安装/卸载: 源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install).   configure文件是一个可执行的脚本文件,它有很多选项, ...

  4. 在Mac上利用压测工具Jmeter-Suite进行一次压测实践的保姆级详细步骤(参考腾讯云文章)

    参考的文章 压测工具Jmeter-Suite详细操作步骤 写此文的目的 由于我是刚开始接触kubernetes和jmeter,所以在学习过程中遇到了很多很多问题,同时我很烦恼为什么网上没有文章是从真正 ...

  5. 转:configure/make/make install的作用 linux 安装 卸载 make uninstall

    这些都是典型的使用GNU的AUTOCONF和AUTOMAKE产生的程序的安装步骤. ./configure 是用来检测你的安装平台的目标特征的.比如它会检测你是不是有CC或GCC,并不是需要CC或GC ...

  6. 在windows下执行./configure,make,makeinstall源码安装程序spice-gtk

    使用MSYS软件,在我的上一篇博客中有软件下载地址.本文使用MSYS进行源码编译spice-gtk-0.33. 首先打开MSYS软件,进入你源码所在目录,例如:cd  /c/Users/Admi... ...

  7. 使用autotools系列工具自动部署源代码编译安装

    在Linux系统下开发一个较大的项目,完全手动建立Makefile是一件费力而又容易出错的工作.autotools系列工具只需用户输入简单的目标文件.依赖文件.文件目录等就可以比较轻松地生成Makef ...

  8. automake - 使用 autotools 工具集

    一般而言,对于小项目或玩具程序,手动编写 Makefile 即可.但对于大型项目,手动编写维护 Makefile 成为一件费时费力的无聊工作. 本文介绍 autotools 工具集自动生成符合 Lin ...

  9. 大型项目使用Automake/Autoconf完成编译配置(标准的编译过程已经变成了简单的三部曲:configure/make/make install,)

    使用过开源C/C++项目的同学们都知道,标准的编译过程已经变成了简单的三部曲:configure/make/make install, 使用起来很方便,不像平时自己写代码,要手写一堆复杂的Makefi ...

随机推荐

  1. lms微服务框架主机介绍

    目录 概念 .net的通用主机 .net的web主机 lms的业务主机类型 用于托管业务应用的普通主机 1. 创建一个应用台程序 2. 安装Silky.Lms.NormHost包 3. 注册LMS服务 ...

  2. Go-16-map

    map的value可以是任何数据类型.map和切片一样,也是一种引用类型. map声明: (1)使用var关键字定义map var 变量名 map[key类型] value 类型 (2)使用make( ...

  3. JDBC_08_解决SQL注入问题 (登录和注册)

    解决SQL注入问题 只要用户提供的信息不参与sql语句的编译过程,那么尽管用户输入的信息中含有sql关键字那么也不会起作用了 要想使用户提供信息不参与sql语句的编译过程,那么必须使用 java.sq ...

  4. 数栈运维实例:Oracle数据库运维场景下,智能运维如何落地生根?

    从马车到汽车是为了提升运输效率,而随着时代的发展,如今我们又希望用自动驾驶把驾驶员从开车这项体力劳动中解放出来,增加运行效率,同时也可减少交通事故发生率,这也是企业对于智能运维的诉求. 从人工运维到自 ...

  5. 01- web测试快速入门

    web测试与APP测试最非常重要的两个测试种类.web端指的就是在浏览器页面的测试. 你测试的软件通常是两种结构的,B/S架构与C/S架构. B/S架构:Browser/Server 浏览器与服务器模 ...

  6. 限制pyqt5应用程序 只允许打开一次

    起因 pyqt5程序创建桌面快捷方式后,多次单击图标 会打开多个UI界面,这种情况肯定是不允许的! 解决 if __name__ == '__main__': try: app = QtWidgets ...

  7. 【Nacos】Springboot整合Nacos配置中心(二) 多环境配置

    本篇随笔接上一篇文章:Springboot整合Nacos配置中心(一),主要记录Nacos多环境的配置的方法 Nacos多环境的配置 方法一: 1.在项目中的bootstrap.yaml文件中配置激活 ...

  8. 【Nginx(一)】Centos下 Nginx环境搭建

    Nginx环境搭建 系统环境: 腾讯云 Linux Centos7 1.下载nginx压缩包 ,上传到腾讯云服务器 http://nginx.org/en/download.html 或者使用dock ...

  9. 【Idea】实用的快捷键清单

    1.Ctrl + Shift +i:快速查看某个类/方法 2.Ctrl +:(Ace Jump插件启动) 3.alt+F1:快速查看某个类/方法 所在的包 4.Ctrl +w :选中某个单词 5.Ct ...

  10. ThinkPHP5 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php

    1.首先修改Apache的httpd.conf文件. 确认httpd.conf配置文件中加载了mod_rewrite.so 模块,加载的方法是去掉mod_rewrite.so前面的注释#号 讲http ...