在linux 中,经常需要用到交叉编译,在ubuntu系统中,交叉编译可以运行在arm平台上的bin文件。对于大部分代码,
都有configure文件,让开发者进行配置,配置完毕之后自动生成makefile,然后进行编译。本文旨在说明configure中
常用的一些参数。
软件环境: ubuntu 操作系统
编译工具链:arm-xilinx-linux-gnueabi
硬件平台:zynq7010
在configure目录下,运行 --help命令,可以查看到configure的配置参数一共有哪些。
./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]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--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/cgminer]
--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]
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
LIBUSB_CFLAGS
C compiler flags for LIBUSB, overriding pkg-config
LIBUSB_LIBS linker flags for LIBUSB, overriding pkg-config
JANSSON_CFLAGS
C compiler flags for JANSSON, overriding pkg-config
JANSSON_LIBS
linker flags for JANSSON, overriding pkg-config
LIBCURL_CFLAGS
C compiler flags for LIBCURL, overriding pkg-config
LIBCURL_LIBS
linker flags for LIBCURL, overriding pkg-config
LIBSYSTEMD_CFLAGS
C compiler flags for LIBSYSTEMD, overriding pkg-config
LIBSYSTEMD_LIBS
linker flags for LIBSYSTEMD, 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.
--build=BUILD configure for building on BUILD [guessed]
build: 执行代码编译的主机,正常的话就是你的主机系统。这个参数一般由config.guess来猜就可以。当然自己指定也可以。可以默认不写,默认为当前正在使用的ubuntu主机,如 i386-linux
--build=i386-linux
或者xilinx-arm的编译器主机
--build=i686-pc-linux-gnu
或者不写
--host=HOST cross-compile to build programs to run on HOST [BUILD]
指定软件运行的系统平台.如果没有指定,将会运行`config.guess’来检测.–host 指定的是交叉编译工具链的前缀。如本位中采用的是arm-xilinx-linux-gnueabi 工具链,则参数配置为:
--host=arm-xilinx-linux-gnueabi
--target=TARGET configure for building compilers for TARGET [HOST]
target: 这个选项只有在建立交叉编译环境的时候用到,正常编译和交叉编译都不会用到。他用build主机上的编译器,编译一个新的编译器(binutils, gcc,gdb等),这个新的编译器将来编译出来的其他程序将运行在target指定的系统上。
如果不编译新的编译器,这个参数可以不填,或者与 host的参数一致
--target=arm-xilinx-linux-gnueabi
或者不写 --target的参数
CC C compiler command
指定GCC 交叉编译器命令,如果配置了,则使用CC配置的编译器,如果不配置则默认为host对应的GCC工具
如配置了 --host=arm-xilinx-linux-gnueabi,则默认CC的编译器为 arm-xilinx-linux-gnueabi-gcc
这个参数如无特殊指定,可以忽略不写。
3.2.5 prefix 安装参数
该参数指定编译后,文件安装的目录。
--program-prefix=PREFIX prepend PREFIX to installed program names
不指定prefix,则可执行文件默认放在/usr/local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc。其他的资源文件放在/usr/local/share。你要卸载这个程序,要么在原来make目录下用make uninstall(前提是make文件指定过make uninstall),要么去上述文件中一个一个手动删除。如需指定make install 的目录,如 /home/tmp/test
--prefix=/home/tmp/test
如编译 zynq平台下的程序,则配置如下即可
./configure --host=arm-xilinx-linux-gnueabi --build=i686-pc-linux-gnu --target=arm-xilinx-linux-gnueabi CC=arm-xilinx-linux-gnueabi-gcc
或者
./configure --host=arm-xilinx-linux-gnueabi --build=i386-linux
或者
./configure --host=arm-xilinx-linux-gnueabi