现在的位置: 首页 > 综合 > 正文

交叉编译的一般方法

2014年10月17日 ⁄ 综合 ⁄ 共 1578字 ⁄ 字号 评论关闭

一般软件包有一个configure或者Configure脚本
执行./configure --help 获取帮助, 查看一下一些feature选项的含义,确定是否需要一些feature项

1.改变安装路径 --prefix
软件编译后一般安装路径是/usr/bin,/usr/lib,/usr/include
例如指定--prefix=$HOME
这安装路径改到$HOME/bin,$HOME/lib,$HOME/include

2. 指定--host=HOST(arm-linux,mips-linux,etc...)

3. 指定交叉编译器 CC, AR, CPP,STRIP这些宏
方法一: export CC=/opt/.../...gcc
方法二: 直接在./configure后跟上 CC=/opt/.../...gcc

终极方法是编辑Makefile, 或者结合Makefile,configure文件先看下configure一些项,必要的编辑一些项

 

有些Makefile已经提供了 CROSS宏 的则相对好改些

 

一个交叉编译例子(转载)

I'm trying to cross-compile NetSNMP 5.4.2 for running on an embedded system(mips).
由于我使用的CPU是little endian 交叉编译工具是 mipsel-linux
如果你用的是Big endian,交叉编译用具就可能是 mips-linux
1. 设置环境变量::

TOOLCHAIN=mipsel-linux-
CC=${TOOLCHAIN}gcc
CPP=${TOOLCHAIN}cpp
AR=${TOOLCHAIN}ar
STRIP=${TOOLCHAIN}strip
RANLIB=${TOOLCHAIN}ranlib
LD=${TOOLCHAIN}ld

2. 编译安装::

../net-snmp-5.4.2.1/configure --build=i686-linux --host=mipsel-linux --target=mipsel-linux --with-transports="UDP"  --prefix=/opt/rootfs/snmp --with-endianness=little --with-persistent-directory=/var/net-snmp/ --with-default-snmp-version="2" --enable-mini-agent --without-kmem-usage --disable-debugging --disable-embedded-perl --without-perl-modules
make
make install

PS: 
     1. 如果你采用的是 Big endian, --with-endianness=little 应该改为 --with-endianness=big
     2. 如果不想对openssl 的支持,用 --without-openssl  

3. 测试::

border@ubuntu:/opt/rootfs/snmp/sbin$ pwd
/opt/rootfs/snmp/sbin
border@ubuntu:/opt/rootfs/snmp/sbin$ file snmpd
snmpd: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
border@ubuntu:/opt/rootfs/snmp/sbin$ file snmptrapd
snmptrapd: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

抱歉!评论已关闭.