zoukankan      html  css  js  c++  java
  • configure.*和Makefile.*之间的关系

        现在很多项目都在使用GUI编译器,KdevelopEclipse等等,诚然它给我们提供了极大地便利,但我们仍需要简单了解编译的过程。本文旨在简单叙述由源码(*.cpp & *.h)经过编译得到可执行文件的过程,以及对生成的中间文件做一个简单的讲解,后面给出一个example。

    image

    相关tips & explanations:

    1. autoscan:扫描源代码以搜寻普通的可移植性问题,比如检查编译器,库,头文件等,生成文件configure.scan,它是configure.ac的一个雏形。

    过程:your source files --> [autoscan*] --> [configure.scan] --> configure.ac

    2. aclocal:根据已经安装的宏,用户定义宏和acinclude.m4文件中的宏将configure.ac文件所需要的宏集中定义到文件aclocal.m4中。

    aclocal是一个perl脚本程序,它的定义是:"aclocal - create aclocal.m4 by scanning configure.ac"

    3. automake:automake将Makefile.am中定义的结构建立Makefile.in。

    然后configure脚本将生成的Makefile.in文件转换 为Makefile。如果在configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOOL,它会调用libtoolize,否则它 会自己产生config.guess和config.sub

    捕获1

    4. autoconf:将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。

    捕获2

    5. ./configure的过程

    捕获3

    6. make过程

    [autoconfig.h]—.
                        +-----> make* ----->程序

    捕获4

    Never mind, That's not a problem~, there is nothing to be afraid of, cause the following example I provided will show you the guide. perhaps you should type the commands one by one for better understanding.

    Example:

    在/home/panda/目录下vi一个hello.cpp文件(当然,你的[*.cpp&*.h]都可以放在这里,但必须保证没有语法上的错误),并complie它:

    >>>>cd /home/panda/hello/

    >>>>vi hello.cpp/*编写源文件hello.cpp*/

    [CODE]

    #include<iostream>

    using namespace std;

    int main()

    {

    cout<<"Hello,RoboCup."<<endl;

    return 0;

    }

    [/CODE]

    >>>>autoscan

    >>>>mv configure.scan configure.in

    >>>>vi configure.in

    /*已经生成了configure.scan,autoscan.log*/

    /*将configure.scan 修改为 configure.in,最后修改的内容如下*/

    [CODE]

    #-*- 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([hello.cpp])

    #AC_CONFIG_HEADER([config.h])

    AM_INIT_AUTOMAKE(hello, 1.0)

    # 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_OUTPUT(Makefile)

    [/CODE]

    >>>>aclocal/*生成 aclocal.m4 和 autom4te.cache (生成aclocal.m4的过程中涉及到configure.in)*/

    >>>>ls

    >>>> aclocal.m4 autom4te.cache autoscan.log configure.in hello.cpp

    >>>>antoconf/*生成 configure (根据 configure.in, 和 aclocal.m4)*/

    >>>>ls

    >>>>aclocal.m4 autom4te.cache autoscan.log configure configure.in hello.cpp

    >>>>vi Makefile.am/*编写Makefile.am*/

    >>>>vi Makefile.am

    /*编写Makefile.am*/

    [CODE]

    AUTOMAKE_OPTIONS= foreign

    bin_PROGRAMS= hello

    hello_SOURCES= hello.cpp

    [/CODE]

    >>>>automake

    >>>>automake --add-missing/*生成 Makefile.in, depcomp, install-sh, 和 missing (根据 Makefile.am, 和 aclocal.m4)*/

    >>>>ls

    >>>>aclocal.m4 autom4te.cache autoscan.log configure configure.in depcomp hello.cpp install-sh Makefile.am Makefile.in missing

    >>>>configure/*Makefile, config.log, 和 config.status*/

    /*红色表示在终端中输入的命令,斜体表示源码*/

    至此大功告成。

    现在看不明白,或者不是很清楚都没有关系,只做了解就好,可以将本文保留下来,随着你们学习的深入,等到时机成熟的时候再作参考,便会对Linux下C++的编译过程会理解的更加透彻。

    Good Luck!

    文档下载链接:http://download.csdn.net/detail/klcf0220/7703221

  • 相关阅读:
    Django学习笔记之Cookie、Session和自定义分页
    sass表达式前后出现空格
    render总结
    vue双向绑定补充说明方法
    mutation与action
    keep-alive使用笔记
    this指向 一般函数与箭头函数
    vue-router原理分析
    history新增方法
    常用阻止ajax缓存方法集锦
  • 原文地址:https://www.cnblogs.com/klcf0220/p/3884798.html
Copyright © 2011-2022 走看看