《2022年Linux下C++编程 .pdf》由会员分享,可在线阅读,更多相关《2022年Linux下C++编程 .pdf(3页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、相关 tips & explanations :autoscan: 扫描源代码以搜寻普通的可移植性问题,比如检查编译器,库,头文件等,生成文件configure.scan,它是configure.ac的一个雏形。1.过程: your source files - autoscan* - configure.scan - configure.acaclocal: 根据已经安装的宏,用户定义宏和acinclude.m4文件中的宏将 configure.ac文件所需要的宏集中定义到文件aclocal.m4中。2.aclocal是一个 perl脚本程序,它的定义是:aclocal - create a
2、clocal.m4 by scanning configure.acautomake:automake将 Makefile.am 中定义的结构建立Makefile.in 。3.然后configure脚本将生成的 Makefile.in 文件转换 为 Makefile 。如果在 configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOOL,它会调用 libtoolize ,否则它 会自己产生 config.guess和config.sub .-, | |- COPYING| |- INSTALL | |- install-sh | |- missing| automake |
3、- mkinstalldirs configure.ac -| | Makefile.am-| |- Makefile.in | |- stamp-h.in .-+ |- config.guess | | |- config.sub | -+- | |- config.guess | libtoolize |- config.sub | |- ltmain.sh | |- ltconfigautoconf:将 configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。4. - aclocal.m4 & autoconfig.h.in -
4、- - - -. V configure.ac -|autoconf|- configure./configure的过程5. .- config.cache configure* -+- config.log | config.h.in -. v .- autoconfig.h +- config.status* -+ Makefile.in - - Makefilemake过程6. autoconfig.h-. +- make* -程序 Makefile-每天都要有记录!每天都要有进步!此文对 RoboCup2D|3D|Rescue等涉及 Linux下C/C+编程的项目均适用现在很多项目都在
5、使用GUI编译器, KdevelopEclipse 等等,诚然它给我们提供了极大地便利,但我们仍需要简单了解编译的过程。本文旨在简单叙述由源码(*.cpp & *.h) 经过编译得到可执行文件的过程,以及对生成的中间文件做一个简单的讲解,后面给出一个example。当然了,一家之言,欢迎拍砖configure.* 和Makefile.* 之间的关系2010 年8月18日 星期三11:04分区 学术杂记的第 1 页名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 3 页 -
6、- - - - - - - - Makefile- .-, config.site - - -| | config.cache - - -| configure | - - - config.cache | +-, -+- | | |- config.status config.h.in -|config- |- config.h Makefile.in -| .status |- Makefile | |- stamp-h | +-, .-+ | | | -+- | ltmain.sh -|ltconfig |-+- libtool | | | -+- | | config.guess |
7、| config.sub | - .-. Makefile -| | config.h -| make | project sources -| |- project targets .-+ +-, | - | | libtool | | missing | | install-sh | | mkinstalldirs | -没看明白?Never mind, Thats not a problem, there is nothing to be afraid of, cause the following example I provided will show you theguide. p
8、erhaps you should type the commands one by onefor better understanding.Example:在/home/panda/ 目录下 vi一个 hello.cpp文件 (当然,你的 *.cpp&*.h 都可以放在这里,但必须保证没有语法上的错误),并 complie它:cd /home/panda/hello/vi hello.cpp /* 编写源文件 hello.cpp*/CODE#includeusing namespace std;int main()coutHello,RoboCup.autoscan /* 已经生成了 con
9、figure.scan,autoscan.log*/mv configure.scan configure.in /* 将configure.scan 修改为 configure.in,最后修改的内容如下*/vi configure.inCODE# -*- 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.cp
10、p)#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)/CODEaclocal /* 生成 aclocal.m4 和 autom4te.cache (
11、生成 aclocal.m4的过程中涉及到configure.in)*/ls aclocal.m4 autom4te.cache autoscan.log configure.in hello.cppantoconf /*生成 configure (根据 configure.in, 和 aclocal.m4)*/lsaclocal.m4 autom4te.cache autoscan.log configure configure.in hello.cppvi Makefile.am /* 编写 Makefile.am*/分区 学术杂记的第 2 页名师资料总结 - - -精品资料欢迎下载 - -
12、 - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 3 页 - - - - - - - - - vi Makefile.am /* 编写 Makefile.am*/CODEAUTOMAKE_OPTIONS= foreignbin_PROGRAMS= hellohello_SOURCES= hello.cpp/CODEautomake automake -add-missing /* 生成 Makefile.in , depcomp, install-sh, 和 missing (根据 Makefile.am, 和 aclo
13、cal.m4)*/lsaclocal.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+的编译过程会理解的更加
14、透彻。by the way, 上次的讲解中有 autoreconf -fvi这个命令 ,这是 autoconf, autoheader, aclocal, automake 几个命令的合体。下面贴上官方解释:autoreconfautoreconf options GNU autoconf tool. Update configure scripts by running autoconf, autoheader, aclocal, automake, and libtoolize in specified directories and subdirectories. This comman
15、d is seldom invoked manually. It is usually called automatically from other autoconf tools.OptionsDont remove temporary files.-d, -debug Remake all configure scripts, even when newer than their template files.-f, -force Print help message, then exit.-h, -help Add any default files missing from packa
16、ge by copying versions included with autoconf and automake.-i, -install Used with the -i option. Create symbolic links to default files instead of copying them.-s, -symlink Verbosely print information about the progress of autoreconf.-v, -verbose Search in directory dir for input files.-I dir, -incl
17、ude=dirPrint version number, then exit.-V, -version Print any warnings related to category. Accepted categories are:Cross compilation.cross Obsolete constructs.obsolete Questionable syntax.syntax All warnings.all Turn off warnings for category.no-categoryTurn off all warnings.none Treat warnings as errors.error Good Luck!_Powered by Panda Chow-W category, -warnings=category分区 学术杂记的第 3 页名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 3 页 - - - - - - - - -
限制150内