给小米路由器上面的python添加扩展库

上次编译python移植的到小米路由器上,http://blog.csdn.net/ftsun123/article/details/24925671,想把goagent 移植到python上面,发现没有openssl支持,调用urllib打开https的网站会有问题,所以我这边添加了对openssl的支持,添加步骤如下。

首先下载openssl的sourcecode http://www.openssl.org/source/

解压后编译,编译环境可以参考编译python的那篇文章,然后执行下面的命令

CC=arm-openwrt-linux-gcc CXX=arm-openwrt-linux-g++ AR=arm-openwrt-linux-ar RANLIB=arm-openwrt-    linux-ranlib ./Configure no-asm shared --prefix=`pwd`/../out/openssl linux-armv4
  2 make
  3 make install

就可以在上级目录的out/openssl 下面生成arm上面需要的openssl库了。

然后修改python的 setup.py文件(记得要先按编译python那篇文章打补丁),在453行添加下面的code。

# The common install prefix of 3rd party libraries used during
 453             # cross compilation
 454             mydir = os.environ.get('PYTHON_XCOMPILE_DEPENDENCIES_PREFIX')
 455             if mydir:
 456                 inc_dirs += [mydir + '/include' ]
 457                 inc_dirs += [mydir + '/lib/libffi-3.0.10/include']
 458                 lib_dirs += [mydir + '/lib' ]
 459             #inc_dirs += [os.getcwd() +'/third/out/zlib/include']
 460             inc_dirs += [os.getcwd() + '/third/out/openssl/include']
 461             #lib_dirs += [os.getcwd() + '/third/out/zlib/lib/']
 462             lib_dirs += [os.getcwd() + '/third/out/openssl/lib/']

重新make 可以发现python 已经不会提示没有_ssl支持了。

安装goagent 还需要安装pyOpenSSL, 这个我是通过easy install 安装,不过依赖的一些库由于包含c文件需要自己手动编译成egg包或lib库安装上去,直接去网上搜一下这些lib,下载下来sourcecode就可以了。

安装pyOpenSSL依赖的需要手动编译的库如下。

cryptography-0.4->cffi-0.8.2->libffi-3.1

首先编译libffi,编译环境还是openwrt

CC=arm-openwrt-linux-gcc CXX=arm-openwrt-linux-g++ AR=arm-openwrt-linux-ar RANLIB=arm-openwrt-linux-ranlib ./configure --host=./configure --host=arm-linux --prefix=`pwd`/../out/libffi
make
make install

编译ciffi-0.8.2

export PLAT=arm-openwrt-linux-
export PY=~/python-arm #python 的编译目录,所有的扩展包我都是放到这个目录下的third目录
export CC="${PLAT}gcc -pthread"
export LDSHARED="${CC} -shared"
export PYPREFIX=${PY}_install/ # python 编译出来的结果
export CFLAGS="-I${PY}/third/out/libffi/include -I${PYPREFIX}include/python2.7"
export LDFLAGS="-L${PY}third/out/libffi/lib"
python setup.py bdist_egg

如果没有错误会在dist目录下生成cffi-0.8.2-py2.7-linux-x86_64.egg 文件,重命名文件cffi-0.8.2.egg 不然安装会有问题。


编译cryptography, 这里需要依赖前面编译出来的openssl lib

export PLAT=arm-openwrt-linux-
export PY=<span style="font-family: Arial, Helvetica, sans-serif;">~/python-arm #python 的编译目录,所有的扩展包我都是放到这个目录下的third目录</span>
export CC="${PLAT}gcc -pthread"
export LDSHARED="${CC} -shared"
export PYPREFIX=“${PY}_install/"
export CFLAGS="-I${PY}third/out/openssl/include -I${PYPREFIX}include/python2.7"
export LDFLAGS="-L${PY}third/out/openssl/lib"<pre name="code" class="plain">python setup.py bdist_egg

 编译出来egg同样需要重命名为cryptography-0.4。 

这样基本需要的egg&lib就编译Ok了,接下来需要安装到路由器上面。

首先安装lib

编辑/etc/profile文件,添加下面的语句

export LD_LIBRARY_PATH=/userdisk/libs/

把编译的openssl,和libcffi都拷贝到这个目录。

安装easy_install 文件

wget http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py

把刚才编译好的cffi和cryptography都拷贝到路由器上面,运行命令

easy_install cffi-0.8.2.egg
ease_install cryptography-0.4.egg
ease_install pyOpenSSL

如果没有问题就安装好了pyOpenSSL库了,这样就可以安装goagent 了,安装方法很多,大家可以自己在网上找。

本来还编译了gevent库,想让goagent 工作的更稳定但是goagent会有Segment fault 错误,测试了一下goagent 被伟大的防火墙也弄的半残了,也就懒得折腾了。知道如何编译python 扩展库就OK了。

后记:

如果有时间看看能不能让路由器识别arduino mega,我这里有块板子,但是插上识别不出来,看来一下好像是没有usb串口驱动没有,有空看看能不能编译一个ipk装上去。







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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值