建立OPENWRT交叉编译环境

Cross Compile

If you want to use a program, currently not contained in the OpenWrt repository, you probably won't find a binary compiled for your CPU. Provided that it is released as open source, you can download the code and compile it using the OpenWrt Buildroot.

Note that not every code is compilable for every CPU architecture. Also performance on embedded systems is limited compared to ordinary computers.

Procedure

  • Follow the build instructions outlined in  OpenWrt Buildroot – Usage
  • Locate the toolchain binaries in the  staging_dir/toolchain-architecture_gcc-compilerver_uClibc-libcver/bin/ directory
  • Add that directory to the  PATH environment variable:
    • PATH=$PATH:(your toolchain/bin directory here)
    • export PATH
  • Set the  STAGING_DIR environment variable to the above toolchain dir and export it:
    • STAGING_DIR=(your toolchain directory here)
    • export STAGING_DIR
  • Download and unpack the code to be compiled, change into the unpacked directory
  • Pass the  host to the build system of the package to compile
    • For GNU configure, use  --host=architecture-openwrt-linux-uclibc (for example:  mips-openwrt-linux-uclibc)
    • For GNU make, override the  CC and  LD environment variables (usually not needed if GNU configure was used)
      • make CC=architecture-openwrt-linux-uclibc-gcc  LD=architecture-openwrt-linux-uclibc-ld
  • If compilation aborts due to missing header files or shared objects, you might need to override  CFLAGS and  LDFLAGS to point to the staging_dir/target-architecture_uClibc-libcver/usr/include and  …/usr/lib directories
  • Debugging requires gdb in the toolchain. Default config does not include it. Include using  make menuconfig. [Advanced configuration options→Toolchain Options→Build gdb]
  • Remote debugging can be done using script  ./scripts/remote-gdb

When compilation is finished, copy the resulting binary and realted libraries to the target device to test it. It might be necessary to set LD_LIBRARY_PATH on the target to point the binary to libraries in nonstandard locations.

If the program works well enough, you maybe want to build a real package for the opkg package manager and make it easily accessible for everyone out there. See Creating your own packages and Using Dependencies for further information on that.


转载自:http://wiki.openwrt.org/doc/devel/crosscompile 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值