由于最近项目需要在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
if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory 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'选项的值.
4、-enable-FEATURE[=ARG]
相反的,一些软件包可能提供了一些默认被禁止的特性,可以使用'--enable-FEATURE'来起用它.这里'FEATURE'是特性的名字.一个特性可能会接受一个可选的参数.例如:
$ ./configure --enable-buffers=128
5、`--enable-FEATURE=no'与上面提到的'--disable-FEATURE'是同义的.
--enable-static:生成静态链接库
--enable-shared:生成动态链接库
这两个用来选择生成是静态库还是动态库,但是我配置了无效,具体我也不知道为什么,希望有了解的不吝赐教。
8、也可以配置它们的环境变量,如:
CC C compiler command
CFLAGS C compiler flags
9、'--prefix=PREFIX'
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下交叉编译需要的环境变量。如果编译的是库文件,就可以把库文件和相应的头文件包含到工程中就可以使用了 。