由于最近项目需要在HMI层生成二维码,所以去网上找了第三方开源库。可是下载下来里面都是源码,没有动态库或者静态库,所以就需要自己去编译生成。源码库中只有一个configure的可运行得配置脚本,之前用过,没有详细了解,今天去网上查阅资料,以下是整理的一些心得笔记。


首先让我们先来了解一下configure这个文件的作用。


Linux环境下的软件安装,并不是一件容易的事情;如果通过源代码编译后再安装,当然事情就更为复杂一些;现在安装各种软件的教程都非常普遍;但万变不离其中,对基础知识的扎实掌握,安装各种软件的问题就迎刃而解了。Configure脚本配置工具就是基础之一,它是autoconf的工具的基本应用。

configure它是个shell脚本,主要用于编译安装源代码库和软件。 ./configure是源代码安装的第一步,主要的作用是对即将安装的软件进行配置,比如加上 –with、–enable、–without、–disable 等等参数对编译加以控制,检查当前的环境是否满足要安装软件的依赖关系,比如它会检测你是不是有CC或GCC,并不是需要CC或GCC。生成makefile文件,以便你可以用make和make install来编译和安装程序,最后运行make clean删除一些临时文件。
首先我们可以使用 ./configure  --help 就可以查看到所有的配置选项。下面我们对一些重要的常见的进行介绍:
Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/qrencode]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-silent-rules   less verbose build output (undo: "make V=1")
  --disable-silent-rules  verbose build output (undo: "make V=0")
  --enable-static[=PKGS]  build static libraries [default=no]
  --enable-dependency-tracking
                          do not reject slow dependency extractors
  --disable-dependency-tracking
                          speeds up one-time build
  --enable-shared[=PKGS]  build shared libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --enable-thread-safety  make the library thread-safe. [default=yes]
  --disable-sdltest       Do not try to compile and run a test SDL program
  --disable-rpath         do not hardcode runtime library paths
  --enable-gprof          generate extra code to write profile information
                          suitable for gprof [default=no]
  --enable-gcov           generate extra code to write coverage information
                          suitable for gcov [default=no]
  --enable-mudflap        generate extra code to check memory leaks
                          [default=no]

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-pic[=PKGS]       try to use only PIC/non-PIC objects [default=use
                          both]
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-sysroot=DIR Search for dependent libraries within DIR
                        (or the compiler's sysroot if not specified).
  --with-tools            build utility tools [default=yes]
  --with-tests            build tests [default=no]
  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)
  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
  --without-libiconv-prefix     don't search for libiconv in includedir and libdir

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor
  PKG_CONFIG  path to pkg-config utility
  PKG_CONFIG_PATH
              directories to add to pkg-config's search path
  PKG_CONFIG_LIBDIR
              path overriding pkg-config's built-in search path
  png_CFLAGS  C compiler flags for png, overriding pkg-config
  png_LIBS    linker flags for png, overriding pkg-config

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.


1、--host=HOST
指定软件运行的系统平台.如果没有指定,将会运行`config.guess'来检测.--host 指定的是交叉编译工具链的前缀

2、--build=BUILD
指定软件包安装的系统平台,如当前我们是在intel的pentium机器中编译该系统,那么我们的--build就可能
是i686-pc-linux-gnu,.如果没有指定,默认值将是'--host'选项的值.


3、--target=GARGET
指定软件面向(target to)的系统平台.这主要在程序语言工具如编译器和汇编器上下文中起作用.如果没有指定,默认将使用'--host'选项的值. 

一般而言,我们只要指定 --host 就可以了,--build和--host不同的时候就被配置文件认定为进行交叉编译,否则就是表示本地编译。
从这三个参数的含义来看,说明其处理的目标只有在不同平台下表现为不同的时候才有作用,而这些文件通常都跟目标平台的指令系统直接或间接关:比如可执行文件,对于不同平台下使用的可执行文件的编码可以是完全不同的,因此必须使用 对应能处理该编码的程序才能正确处理,而如果错误的使用则可能导致程序错误或者破坏文件,对于这样要处理不同平台下会 出现不同编码的软件,我们就应当对它指定目标平台,以免另其错误处理;而对于文本文件,对于不同的平台同样的内容表达的 含义都是相同的,因此我们不需要专门针对平台来处理,这样的软件我们就可以不必对它指定需要处理的平台了。
在交叉编译之后,可以用file *** 指令,查看生成的文件的类型,如果不对的话,就可以去查看config.log文件,看看有没有找到相应的编译工具链。


4、-enable-FEATURE[=ARG]
相反的,一些软件包可能提供了一些默认被禁止的特性,可以使用'--enable-FEATURE'来起用它.这里'FEATURE'是特性的名字.一个特性可能会接受一个可选的参数.例如:
$ ./configure --enable-buffers=128

5、`--enable-FEATURE=no'与上面提到的'--disable-FEATURE'是同义的.

--enable-static:生成静态链接库

--enable-shared:生成动态链接库

这两个用来选择生成是静态库还是动态库,但是我配置了无效,具体我也不知道为什么,希望有了解的不吝赐教。

6、'--with-PACKAGE[=ARG]'
在自由软件社区里,有使用已有软件包和库的优秀传统.当用'configure'来配置一个源码树时,可以提供其他已经安装的软件包的信息.例如,倚赖于Tcl和Tk的BLT器件工具包.要配置BLT,可能需要给'configure'提供一些关于我们把Tcl和Tk装的何处的信息: 
$ ./configure --with-tcl=/usr/local --with-tk=/usr/local

'--with-PACKAGE=no'与下面将提到的'--without-PACKAGE'是同义的.

7、'--without-PACKAGE'
有时候你可能不想让你的软件包与系统已有的软件包交互.例如,你可能不想让你的新编译器使用GNU ld.通过使用这个选项可以做到这一点:
$ ./configure --without-gnu-ld


8、也可以配置它们的环境变量,如:

<span style="font-family:SimSun;font-size:14px;">  CC          C compiler command
  CFLAGS      C compiler flags</span>
9、'--prefix=PREFIX'
'--prefix'是最常用的选项.制作出的'Makefile'会查看随此选项传递的参数,当一个包在安装时可以彻底的重新安置他的结构独立部分.
举一个例子,当安装一个包,例如说Emacs,下面的命令将会使Emacs Lisp file被安装到"/opt/gnu/share":
$ ./configure --prefix=/opt/gnu


10、'--bindir=DIR'
指定二进制文件的安装位置.这里的二进制文件定义为可以被用户直接执行的程序.

11、'--sbindir=DIR'
指定超级二进制文件的安装位置.这是一些通常只能由超级用户执行的程序.


12、'--libdir=DIR'
指定库文件的安装位置.

13、'--includedir=DIR'
指定C头文件的安装位置.其他语言如C++的头文件也可以使用此选项.

更为详细的参数的介绍请参考:http://blog.csdn.net/williamwang2013/article/details/8529954

http://blogger.org.cn/blog/more.asp?name=lhwork&id=22496

在此之后,就会自动生成Makefile文件,如果要修改编译器环境等,可以这个时候修改生成的Makefile文件,也可以在。/configure之前,先source下交叉编译需要的环境变量。如果编译的是库文件,就可以把库文件和相应的头文件包含到工程中就可以使用了 。




Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐