最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【整理】交叉编译心得和注意事项

CrossCompiler crifan 8005浏览 0评论

【背景】

最近折腾了用crosstool-ng在cygwin和Ubuntu下面的:

制作交叉工具链:

【记录】重试使用最新版本1.18.0的crosstool-ng去配置和编译xscale的交叉编译器

【记录】Ubuntu下用crosstool-ng为xscale建立交叉编译器arm-xscale-linux-gnueabi-gcc

用交叉编译器去编译各种库:

 

【记录】Cygwin下用arm-xscale-linux-gnueabi交叉编译xmlrpc

【记录】Cygwin下用arm-xscale-linux-gnueabi-gcc交叉编译curl(libcurl)

【记录】Cygwin下用arm-xscale-linux-gnueabi交叉编译libxml2

【记录】Cygwin下用arm-xscale-linux-gnueabi交叉编译log4c

【记录】Cygwin下用arm-xscale-linux-gnueabi交叉编译expat

【记录】用交叉编译器arm-xscale-linux-gnueabi交叉编译一个基于嵌入式Linux的无线HART的项目

 

【记录】Ubuntu下用arm-xscale-linux-gnueabi交叉编译xmlrpc

【记录】Ubuntu下用arm-xscale-linux-gnueabi交叉编译curl(libcurl)

【记录】Ubuntu下用arm-xscale-linux-gnueabi交叉编译libxml2

 

然后对于交叉编译,有点心得,现总结如下:


交叉编译库时所最常用到的配置

由:

软件开发基础之linux下安装某个软件的逻辑和过程

而知,一般编译都是:

./configure xxx

make

make install

此处,对于./configure的xxx,我最常用的是:

./configure --prefix=YOUR_INSTALL_PATH --build=CURRENT_ENV --target=CROSS_COMPILER --host=CROSS_COMPILER CC=CROSS_COMPILER-gcc OTHER_PARAMETER

其中:

–prefix=YOUR_INSTALL_PATH

即,你所要把当前的库,在编译完毕之后,安装到哪里

举例:

【记录】Ubuntu下用arm-xscale-linux-gnueabi交叉编译xmlrpc

中的:

./configure --prefix=/opt/crosscompile/xmlrpc --build=i686-pc-linux-gnu --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi CC=arm-xscale-linux-gnueabi-gcc

 

–build=CURRENT_ENV

目前我遇到的有两种:

关于其值的来历:

(1)其中,此build的值,我之前是参考:

【记录】crosstool为xscale编译(ct-ng build)过程

中的输出:

[EXTRA]  Dumping internal crosstool-NG configuration
[EXTRA]    Building a toolchain for:
[EXTRA]      build  = i686-pc-cygwin
[EXTRA]      host   = i686-pc-cygwin
[EXTRA]      target = arm-xscale-linux-gnueabi

而知道的。

(2)其中,此处的build的值,也是参考:

【记录】Ubuntu下用crosstool-ng为xscale建立交叉编译器arm-xscale-linux-gnueabi-gcc

->

【已解决】Ubuntu中crosstool-ng编译出错:[ERROR] Missing: ‘i686-pc-linux-gnu-g++’ or ‘i686-pc-linux-gnu-g++’ or ‘g++’ : either needed!

中的输出:

[EXTRA]  Dumping internal crosstool-NG configuration
[EXTRA]    Building a toolchain for:
[EXTRA]      build  = i686-pc-linux-gnu
[EXTRA]      host   = i686-pc-linux-gnu
[EXTRA]      target = arm-xscale-linux-gnueabi

才知道的。

 

–target=CROSS_COMPILER和–host=CROSS_COMPILER

对于target和host,此处,都是设置的是交叉编译器的(前缀)。

比如,如果你的交叉编译器是arm-linux,那就是:

--target=arm-linux --host=arm-linux

我此处,用crosstool-ng编译出来的for xscale的交叉编译器是:arm-xscale-linux-gnueabi

所以,此处后续编译各种库,都是用的是:

--target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi

举例:

1. 【记录】Cygwin下用arm-xscale-linux-gnueabi交叉编译log4c

中的:

./configure --prefix=$HOME/develop/crosstool-ng/x-tools/armxscalelog4c --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi --with-expat-prefix=$HOME/develop/crosstool-ng/x-tools/armxscaleexpat CC=arm-xscale-linux-gnueabi-gcc

2.【记录】Ubuntu下用arm-xscale-linux-gnueabi交叉编译curl(libcurl)

中的:

./configure --prefix=/opt/crosscompile/curl --build=i686-pc-linux-gnu --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi CC=arm-xscale-linux-gnueabi-gcc --enable-static

 

CC=CROSS_COMPILER-gcc

1.此处的CC参数,是用于指定编译器用哪个。

一般都是对应的交叉编译器的前缀,加上gcc,比如:

arm-linux的话,加上gcc就是:arm-linux-gcc

arm-xscale-linux-gnueabi加上gcc,就是:arm-xscale-linux-gnueabi-gcc

2.而且,也多数都是可以在./configure时,就设置好对应的CC的值的。

举例:

【记录】Ubuntu下用arm-xscale-linux-gnueabi交叉编译curl(libcurl)

中的:

./configure --prefix=/opt/crosscompile/curl --build=i686-pc-linux-gnu --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi CC=arm-xscale-linux-gnueabi-gcc --enable-static

之后,直接去make即可。

 

但是也有例外:

【记录】cygwin下用arm-xscale-linux-gnueabi交叉编译libcgi

中,由于configure不支持设置CC,所以需要放到后面的make才行,即:

./configure --prefix=$HOME/develop/crosstool-ng/x-tools/libcgi --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi
make CC=arm-xscale-linux-gnueabi-gcc

 

OTHER_PARAMETER

1../configure可以去添加你所需要的参数

但是一般都支持的规则是:

–enable-xxx:启用(编译)某个子模块或功能(feature)

–disable-xxx:禁止(不编译)某个子模块或功能(feature)

 

–with-xxx:类似于–enable-xxx

–without-xxx:类似于–disable-xxx

 

举例:

【记录】Ubuntu下用arm-xscale-linux-gnueabi交叉编译libxml2

中,经过调试错误,发现就不需要编译python,所以,可以去添加对应的

--without-python

去禁止编译python。

所用的配置就是:

./configure --prefix=/opt/crosscompile/libxml2 --build=i686-pc-linux-gnu --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi CC=arm-xscale-linux-gnueabi-gcc --without-python

 

2.添加参数之前,需要搞清楚,当前你所要去编译的库,本身支持什么参数。

正常都是可以通过:

./configure --help

去查看到,当前模块,所支持哪些参数。

举例:

【记录】Cygwin下用arm-xscale-linux-gnueabi-gcc交叉编译curl(libcurl)

中就可以通过

./configure --help

而看到当前的curl支持很多参数,其中包括:

Optional Features:
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-maintainer-mode  enable make rules and dependencies not useful
                          (and sometimes confusing) to the casual installer
  --enable-debug          Enable debug build options
  --disable-debug         Disable debug build options
  --enable-optimize       Enable compiler optimizations
  --disable-optimize      Disable compiler optimizations
  --enable-warnings       Enable strict compiler warnings
  --disable-warnings      Disable strict compiler warnings
  --disable-dependency-tracking  speeds up one-time build
  --enable-dependency-tracking   do not reject slow dependency extractors
  --disable-largefile     omit support for large files
  --enable-shared[=PKGS]  build shared libraries [default=yes]
  --enable-static[=PKGS]  build static libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --enable-http           Enable HTTP support
  --disable-http          Disable HTTP support
  --enable-ftp            Enable FTP support
  --disable-ftp           Disable FTP support
  --enable-file           Enable FILE support
  --disable-file          Disable FILE support
  --enable-ldap           Enable LDAP support
  --disable-ldap          Disable LDAP support
  --enable-ldaps          Enable LDAPS support
  --disable-ldaps         Disable LDAPS support
  --enable-proxy          Enable proxy support
  --disable-proxy         Disable proxy support
  --enable-dict           Enable DICT support
  --disable-dict          Disable DICT support
  --enable-telnet         Enable TELNET support
  --disable-telnet        Disable TELNET support
  --enable-tftp           Enable TFTP support
  --disable-tftp          Disable TFTP support
  --enable-manual         Enable built-in manual
  --disable-manual        Disable built-in manual
  --enable-libgcc         use libgcc when linking
  --enable-ipv6           Enable ipv6 (with ipv4) support
  --disable-ipv6          Disable ipv6 support
  --disable-thread        don't look for thread-safe functions
  --enable-thread         look for thread-safe functions
  --enable-nonblocking    Enable non-blocking communications
  --disable-nonblocking   Disable non-blocking communications
  --enable-ares=PATH      Enable c-ares for name lookups
  --disable-ares          Disable c-ares for name lookups
  --enable-verbose        Enable verbose strings
  --disable-verbose       Disable verbose strings
  --enable-sspi           Enable SSPI
  --disable-sspi          Disable SSPI
  --enable-crypto-auth    Enable cryptographic authentication
  --disable-crypto-auth   Disable cryptographic authentication
  --enable-cookies        Enable cookies support
  --disable-cookies       Disable cookies support
  --enable-hidden-symbols Hide internal symbols in library
  --disable-hidden-symbols
                          Leave all symbols with default visibility in library
  --enable-soname-bump    Enable enforced SONAME bump
  --disable-soname-bump   Disable enforced SONAME bump
 
Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-pic              try to use only PIC/non-PIC objects [default=use
                          both]
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-ldap-lib=libname Specify name of ldap lib file
  --with-lber-lib=libname Specify name of lber lib file
  --with-krb4-includes=DIR
                          Specify location of kerberos4 headers
  --with-krb4-libs=DIR    Specify location of kerberos4 libs
  --with-krb4=DIR         where to look for Kerberos4
  --with-spnego=DIR       Specify location of SPNEGO library fbopenssl
  --with-gssapi-includes=DIR
                          Specify location of GSSAPI header
  --with-gssapi-libs=DIR  Specify location of GSSAPI libs
  --with-gssapi=DIR       Where to look for GSSAPI
  --with-ssl=PATH         Where to look for OpenSSL, PATH points to the SSL
                          installation (default: /usr/local/ssl); when
                          possible, set the PKG_CONFIG_PATH environment
                          variable instead of using this option
  --without-ssl           disable OpenSSL
  --with-zlib=PATH        search for zlib in PATH
  --without-zlib          disable use of zlib
  --with-libssh2=PATH     Where to look for libssh2, PATH points to the
                          LIBSSH2 installation (default: /usr/local/lib); when
                          possible, set the PKG_CONFIG_PATH environment
                          variable instead of using this option
  --without-libssh2       disable LIBSSH2
  --with-egd-socket=FILE  Entropy Gathering Daemon socket pathname
  --with-random=FILE      read randomness from FILE (default=/dev/urandom)
  --with-gnutls=PATH      where to look for GnuTLS, PATH points to the
                          installation root (default: /usr/local/)
  --without-gnutls        disable GnuTLS detection
  --with-nss=PATH         where to look for NSS, PATH points to the
                          installation root (default: /usr/local/)
  --without-nss           disable NSS detection
  --with-ca-bundle=FILE   File name to use as CA bundle
  --without-ca-bundle     Don't use a default CA bundle
  --with-ca-path=DIRECTORY
                          Directory to use as CA path
  --without-ca-path       Don't use a default CA path
  --with-libidn=PATH      Enable libidn usage
  --without-libidn        Disable libidn usage

而对应的,后来经过参考别人的配置,加上了这个:

--enable-static

去实现对应的,支持静态库的效果。

所用配置就是:

./configure --prefix=$HOME/develop/crosstool-ng/x-tools/armxscalecurl --build=i686-pc-cygwin --host=arm-linux CC=arm-xscale-linux-gnueabi-gcc --enable-static

转载请注明:在路上 » 【整理】交叉编译心得和注意事项

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 厉害了!
    Aether8年前 (2017-03-15)回复
85 queries in 0.200 seconds, using 22.15MB memory